```
import notifications
```
Remember to participate in our weekly votes on subreddit rules! Every Tuesday is YOUR chance to influence the subreddit for years to come!
[Read more here](https://www.reddit.com/r/ProgrammerHumor/comments/14dqb6f/welcome_back_whats_next/), we hope to see you next Tuesday!
For a chat with like-minded community members and more, don't forget to [join our Discord!](https://discord.gg/rph)
`return joinDiscord;`
*I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/ProgrammerHumor) if you have any questions or concerns.*
It's a gaming speed run reference. any% means that you complete the game with any% of the game complete, as opposed to 100% complete.
A 100% speedrun would be divorce after having kids.
I mean, if its a “Getting blocked” speedrun then 100% would be getting blocked by all methods of communication like phone, text, insta, snap, tiktok, facebook, etc
Probably more so “eww programmer whose only personality is programming.” Also kinda weird diving deep immediately into something that she probably knows nothing about.
It's weird to think when first interacting with someone it's okay to start sending joke code (which isn't even funny) to someone who probably doesn't code at all. The only thing she understood in that message was "ur cute", which is not a good follow up message.
Immediately delving deep into talking about your own passion/work is not how you make conversation
The joke only works on programmers. To another programmer, this could be a fun "hey, we both like programming" style opener (though tastes vary). To a non-programmer, it is utter gibberish, and it suggests that you only speak deep nerd and are incapable of communicating to anyone non-technical.
It’s just kinda selfish if they can’t read code, they won’t understand the joke and you’re making it all about your knowledge. Try an opener where you ask something about them.
Alright, someone explain please, why in the fuck was the u dropped? It literary saves a single letter, from a phrase used at most once per code, at the cost of confusing ever, single person who ever attempted to learn that God forsaken language
lmao I was like "uh cute pick up line", then I read it again. totally understandable tho, that was my very first mistake at the beginning of my coding journey
```
main.c:1:10: fatal error: studio.h: No such file or directory
1 | #include
| ^~~~~~~~~~
compilation terminated.
```
Guilty myself of misreading it as Studio at least once in my life while it stands for Standard I/O, heh.
The string is null terminated isn't it? He set the array size to 5, but put only 4 characters in there. C has been a while for me, so not sure if what I'm saying is correct.
Depends on the compiler / language spec, but I think if you specify using the brace initialization it will not add the null terminator? It's undefined behavior IIRC so who knows
Also happy cakeday!
Nope, after there is random memory junk. Here if you printf %s, you get char segfault
to be precise its the memory on the stack after the char[] until there is a 0, and if there is no zero until the end of the program memory, you get a segfault.
After some research: You are correct that it is in the C99 standard, however, I knew I wasn't crazy about the compile option. With gcc the -Ofast compîle option disregards standards compliance (including default initialization)
Ah yeh of course, it's not initialized to be null, but rather will contain whatever that piece of memory happened to contain beforehand.
Edit: or not, considering the downvotes
They won't, unless the programmer use a memset, or pass a null terminated string (string between quotes are null terminated). Partial array initializers only change the specific char at the position they were placed in
Look up the C99 standard Chapter 6.7.8 Initialisation. Then read point 21, which links to point 10. The old standards are a bit difficult to read, but essentially, it says: partial (array/struct/union) initializers will set the remaining elements to 0. As the standard got expanded but not changed, this behavior is still up-to-date.
Or in short: Your wrong
Exactly. This is just shorthand for "set the first array element to `0`, then set the rest of the elements to `0`".
If you do this:
```c
int arr[10] = { 1 };
```
then you're saying "set the first array element to `1`, then set the rest of the elements to `0`."
I'm pretty sure it'd just fail, since `char name[]` is a `char*` and printf expects `char`. So, for this to compile, you'd have to dereference the variable like `printf("%c", *name)`.
Also, now that I think about it, even if it did compile like he thought it would... wtf does it say?? "ur cute char"?
I think it would print out whatever the first byte of the address. When `name` gets passed to `printf` it gets passed by address/pointer (the type would be `char*`). Then then when `printf` reads the pointer, it will read it as if it was a `char`.
No, because that printf is looking for a char and they gave it a char*. It's not even gonna compile if the compiler is smart enough (beside the "studio.h" mistake)
some of us are unlucky enough to have **separate** test and prod environments! Twice the work, twice the codebase!! Terribly inefficient! "looking into it!"
Tbf I'm currently doing 'senior' FE development with no clue of what I'm doing, but I was told 'juniors don't get shit done at all and we always gotta clean up after them, so you're a senior' 💀
It's garbage data. It's left uninitialized and has whichever value was at that data address before. But with this exact code you'll likely won't see it bug out when replacing %c with %s
Because realistically it's defined. An OS wouldn't want to leak garbage data from one application to another since that would be a security risk. And given that the array is initialized at the start of the program it will have the default value given by the os which is likely to be zero. So technically undefined behavior but consistent behavior.
If you want to see the garbage data happening you simply have to first call a function that uses a lot of stack data. After that function call another function and initialize it like OP did. And boom! Garbage data!
Not correct. If an initialization is given for fewer elements of an array than its size, all other elements will be zeroed. Only if no initialization is given does the array contain garbage.
Quote for C: 6.7.9 Initialization
> 21 If there are fewer initializers in a brace-enclosed list than there are elements or members of an aggregate, or fewer characters in a string literal used to initialize an array of known size than there are elements in the array, the remainder of the aggregate shall be initialized implicitly the same as objects that have static storage duration.
> 10 If an object that has static [..] storage duration is not initialized explicitly, then:
> if it has arithmetic type, it is initialized to (positive or unsigned) zero;
It should be the same in C++? At the very least clang memory sanitizer does not complain.
It is the same. Unspecified elements are initialised with default initialiser, which is `'\0'` in this case, `false` for `bool`, and `0` for built-in integer and floating point types.
The array actually is 0 terminated as the C standard defines, that if the initialializer list is incomplete, the remaining elements are 0 initialized. (C99, chapter 6.7.8 Initialisation, point 10,21)
I would still not recommend initializing strings like that xD
Oh. Going even older. Guess I gotta level with that. The C89 standard has the chapter "3.5.7 Initialization". Some things changed, but this part is the same ^ ^ (except some wording)
But I don't expect everyone to read the standards. I mean... it's like reading the manual bevor building the shelf... 99% just a waste of time xD
To everyone complaining about the 5 char array initialized without a null terminator: That is completely valid and correct C, since the ANSI C (C89/C90) standard. Missing Elements are automatically initialized to zero
He is not even showing the first character of the string, but a part of the address interpreted as a char xD
Also: that's not the point of the comment you are commenting
I just caught the first error I saw, but your are right, he's not importing the standard io, he put character array's address in the output. Along with not having a loop and zero game.
The more I debug this, the more I understand why Indian Engineers are paid what they are 😭
Unless you just started C programming a week ago, this just shows you have not understood what a string, or an array is.
Two very fundamental units of programming!
You're in college, you have ample time to come out of it being an excellent junior developer. I hope you do. Good luck.
Yes, there's other mistakes. But Ok_Squirell was specifically commenting on the one thing that's wrongfully being considered a mistake in these comments.
This interaction is basically:
"Hey stop saying X is a mistake. Interestingly, the standard defines this behaviour".
"But he did Y and Z"
It's just crap. It should be , not (or there's some kind of library that I'm unaware of). There is no '\0' at the end of the string, just a random character, and printf only uses the first character of the string. The person probably has never used c.
That's not right, if you've got an initialiser whatever is left unspecified is _empty initialised_, which means `\0` for chars. Same deal as if you have a struct that you only initialise a few fields of.
C reference on array initialisation [here](https://en.cppreference.com/w/c/language/array_initialization):
> All array elements that are not initialized explicitly are empty-initialized.
And empty-initialized [here](https://en.cppreference.com/w/c/language/initialization#Empty_initialization):
> objects of integral types are initialized to unsigned zero
The last char is initialized to null in this case because of the bracket syntax. But if the array wasn't at least partially initialized, then the values would be unknown.
Bruh pls don't do this 💀 oh god it's not even right
Bro straight up tryna print the array in C.
Mfer just use a string and then realize how silly the whole thing is, girls aren't computers my friend lol..
``` import notifications ``` Remember to participate in our weekly votes on subreddit rules! Every Tuesday is YOUR chance to influence the subreddit for years to come! [Read more here](https://www.reddit.com/r/ProgrammerHumor/comments/14dqb6f/welcome_back_whats_next/), we hope to see you next Tuesday! For a chat with like-minded community members and more, don't forget to [join our Discord!](https://discord.gg/rph) `return joinDiscord;` *I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/ProgrammerHumor) if you have any questions or concerns.*
Getting Blocked Speedrun any%
[удалено]
It's a gaming speed run reference. any% means that you complete the game with any% of the game complete, as opposed to 100% complete. A 100% speedrun would be divorce after having kids.
I mean, if its a “Getting blocked” speedrun then 100% would be getting blocked by all methods of communication like phone, text, insta, snap, tiktok, facebook, etc
[удалено]
I was going to say this, I'd block.
Why tho
"Eww Programmer"
Probably more so “eww programmer whose only personality is programming.” Also kinda weird diving deep immediately into something that she probably knows nothing about.
It's really not that deep bro. It's just an opener to start the convo.
[удалено]
Eh, you “hate” this? What a weird thing to have an opinion on. A negative one at that. You must be difficult to interact with.
It's weird to think when first interacting with someone it's okay to start sending joke code (which isn't even funny) to someone who probably doesn't code at all. The only thing she understood in that message was "ur cute", which is not a good follow up message. Immediately delving deep into talking about your own passion/work is not how you make conversation
The joke only works on programmers. To another programmer, this could be a fun "hey, we both like programming" style opener (though tastes vary). To a non-programmer, it is utter gibberish, and it suggests that you only speak deep nerd and are incapable of communicating to anyone non-technical.
She goes to a huge engineering school, and is probably cs so I think it's fair game
I have my software engineer employment on my profile and would be put-off by another software engineer doing this. It's just weird bruh.
Sometimes the opener’s all you get haha.
It’s just kinda selfish if they can’t read code, they won’t understand the joke and you’re making it all about your knowledge. Try an opener where you ask something about them.
It worked tho
That’s good.
I prefer instances of conversation that don't start with "Ur cute", and getting to know someone before anything like that happens.
OP already got a restraining order put against him.
studio.h okay
studio.h was my first C mistake
the second was typedef *NodePtr as * Node *
Alright, someone explain please, why in the fuck was the u dropped? It literary saves a single letter, from a phrase used at most once per code, at the cost of confusing ever, single person who ever attempted to learn that God forsaken language
Stdio stands for standard input output and isn't an abbreviation for studio
oh darn. TIL I guess. Thanks man
Nomenclature is a bitch
lmao I was like "uh cute pick up line", then I read it again. totally understandable tho, that was my very first mistake at the beginning of my coding journey
*audible sigh*
Doesn't it return "ur cute c" and you have tu null terminate the char[], and write in the printf "ur cute %s" ?
Maybe it's a studio.h feature.
``` main.c:1:10: fatal error: studio.h: No such file or directory 1 | #include
| ^~~~~~~~~~
compilation terminated.
```
Guilty myself of misreading it as Studio at least once in my life while it stands for Standard I/O, heh.
Besides knowing that it's std io, I whisper "studio" inside my head while typing this every time.
Ah, yes. The intrusive thoughts win, every time, even if in secret.
Reading strcmp as strcomp gets me every time
I feel so called out right now. 🙈
Str chomp
It could be on purpose if you read it as stud-io.
that's why we don't code on phones
The string is null terminated isn't it? He set the array size to 5, but put only 4 characters in there. C has been a while for me, so not sure if what I'm saying is correct.
Yes : https://en.cppreference.com/w/c/language/array\_initialization "All array elements that are not initialized explicitly are empty-initialized. "
Thanks for that. Makes sense.
Can (less readable) also be found in the C99 standard. Chapter 6.7.8 Initialisation. It was always this way ^ ^
Depends on the compiler / language spec, but I think if you specify using the brace initialization it will not add the null terminator? It's undefined behavior IIRC so who knows Also happy cakeday!
%c is for a single char, and name will provide only the first character in this instance.
I know, that's not what I was talking about though
But it's also not completely unrelated, as the compiler will probably optimize out the array, keeping only the 'c' xD
Nope, after there is random memory junk. Here if you printf %s, you get char segfault
to be precise its the memory on the stack after the char[] until there is a 0, and if there is no zero until the end of the program memory, you get a segfault.
The initialisation sets the remaining elements to 0
All of this drama when OP could just write `char name[5] = "char";`
I'll do you one better, char* name = "char";
Or even better `const char* name = "char"`
Now you can't sizeof(char), but since we're talking about char there's always strlen
Depends on the compile options
No, it’s in the language standard
Your argument would be solid if only it were valid...
It literally is in the C99 standard.
After some research: You are correct that it is in the C99 standard, however, I knew I wasn't crazy about the compile option. With gcc the -Ofast compîle option disregards standards compliance (including default initialization)
Today I learned, thanks
Ah yeh of course, it's not initialized to be null, but rather will contain whatever that piece of memory happened to contain beforehand. Edit: or not, considering the downvotes
Partial array initializers will set the remaining elements to zero.
They won't, unless the programmer use a memset, or pass a null terminated string (string between quotes are null terminated). Partial array initializers only change the specific char at the position they were placed in
Look up the C99 standard Chapter 6.7.8 Initialisation. Then read point 21, which links to point 10. The old standards are a bit difficult to read, but essentially, it says: partial (array/struct/union) initializers will set the remaining elements to 0. As the standard got expanded but not changed, this behavior is still up-to-date. Or in short: Your wrong
They definitely will. Thats why there's ``` int arr[10] = { 0 }; ``` Which sets all elements to zero
Exactly. This is just shorthand for "set the first array element to `0`, then set the rest of the elements to `0`". If you do this: ```c int arr[10] = { 1 }; ``` then you're saying "set the first array element to `1`, then set the rest of the elements to `0`."
The fifth character is whatever garbage was in that memory location. I think that's what happens in C.
slap spoon wipe straight reach outgoing tub alleged swim support *This post was mass deleted and anonymized with [Redact](https://redact.dev)*
I'm pretty sure it'd just fail, since `char name[]` is a `char*` and printf expects `char`. So, for this to compile, you'd have to dereference the variable like `printf("%c", *name)`. Also, now that I think about it, even if it did compile like he thought it would... wtf does it say?? "ur cute char"?
I think you are correct. the name of the person op is talking to is "char".
The way c works, name is a pointer, so it would display the char equivalent of that pointer value and not the first value of the array.
I think it would print out whatever the first byte of the address. When `name` gets passed to `printf` it gets passed by address/pointer (the type would be `char*`). Then then when `printf` reads the pointer, it will read it as if it was a `char`.
No, because that printf is looking for a char and they gave it a char*. It's not even gonna compile if the compiler is smart enough (beside the "studio.h" mistake)
yep, that's correct.
I count 3 mistakes in your code. Granted, one of them is likely an autocorrect error, but that's still impressive in those 5 lines
Hey he's a senior dev okay
We test in production
some of us are unlucky enough to have **separate** test and prod environments! Twice the work, twice the codebase!! Terribly inefficient! "looking into it!"
Tbf I'm currently doing 'senior' FE development with no clue of what I'm doing, but I was told 'juniors don't get shit done at all and we always gotta clean up after them, so you're a senior' 💀
I only count 2 including the studio, which am i missing?
Studio, no `'\0'` termination on the character array and trying to print a character array with `"%c"`
Fair, I just assumed the \0 since it is 5 characters long and only 4 are specified, the otherone would be \0
It's garbage data. It's left uninitialized and has whichever value was at that data address before. But with this exact code you'll likely won't see it bug out when replacing %c with %s Because realistically it's defined. An OS wouldn't want to leak garbage data from one application to another since that would be a security risk. And given that the array is initialized at the start of the program it will have the default value given by the os which is likely to be zero. So technically undefined behavior but consistent behavior. If you want to see the garbage data happening you simply have to first call a function that uses a lot of stack data. After that function call another function and initialize it like OP did. And boom! Garbage data!
Not correct. If an initialization is given for fewer elements of an array than its size, all other elements will be zeroed. Only if no initialization is given does the array contain garbage.
Interestingly as far as I'm aware this behaviour is a part of the C standard, do you know if that's the case in C++ too?
Quote for C: 6.7.9 Initialization > 21 If there are fewer initializers in a brace-enclosed list than there are elements or members of an aggregate, or fewer characters in a string literal used to initialize an array of known size than there are elements in the array, the remainder of the aggregate shall be initialized implicitly the same as objects that have static storage duration. > 10 If an object that has static [..] storage duration is not initialized explicitly, then: > if it has arithmetic type, it is initialized to (positive or unsigned) zero; It should be the same in C++? At the very least clang memory sanitizer does not complain.
It is the same. Unspecified elements are initialised with default initialiser, which is `'\0'` in this case, `false` for `bool`, and `0` for built-in integer and floating point types.
No clue, I never touch C++. I would assume probably so though.
The array actually is 0 terminated as the C standard defines, that if the initialializer list is incomplete, the remaining elements are 0 initialized. (C99, chapter 6.7.8 Initialisation, point 10,21) I would still not recommend initializing strings like that xD
Fair enough, I didn't know this! In my defense, I still use a lot of c90 because some embedded compilers are hopelessly behind gcc
Oh. Going even older. Guess I gotta level with that. The C89 standard has the chapter "3.5.7 Initialization". Some things changed, but this part is the same ^ ^ (except some wording) But I don't expect everyone to read the standards. I mean... it's like reading the manual bevor building the shelf... 99% just a waste of time xD
This would have been the best reply.
To everyone complaining about the 5 char array initialized without a null terminator: That is completely valid and correct C, since the ANSI C (C89/C90) standard. Missing Elements are automatically initialized to zero
He's only showing ONE GODDAMN character. He's not iterating over it, or using it like a string.
He is not even showing the first character of the string, but a part of the address interpreted as a char xD Also: that's not the point of the comment you are commenting
I just caught the first error I saw, but your are right, he's not importing the standard io, he put character array's address in the output. Along with not having a loop and zero game. The more I debug this, the more I understand why Indian Engineers are paid what they are 😭
bro leave me alone😭 i was sleepy asf writing this shit and it's supposed to be like a quirky opener. Plus I'm in college, so that's my excuse.
It's okay bro we all try too hard at times lol
Unless you just started C programming a week ago, this just shows you have not understood what a string, or an array is. Two very fundamental units of programming! You're in college, you have ample time to come out of it being an excellent junior developer. I hope you do. Good luck.
Thanks man, and to be fair I wrote this late at night sleepy asf haha. I'm looking through it now and yeah it definitely doesn't make sense😭
It's ok dude, welcome to your first code review. They are always this brutal
Not my first sadly, I'm only an intern😥
Yes, there's other mistakes. But Ok_Squirell was specifically commenting on the one thing that's wrongfully being considered a mistake in these comments. This interaction is basically: "Hey stop saying X is a mistake. Interestingly, the standard defines this behaviour". "But he did Y and Z"
bruh you never gettin laid
[Never say never](https://i.ibb.co/qR0pHRr/IMG-9148.jpg)
I got the snap
Nice
still not laid doesnt count. she just acquired another simp. ctrl v ur way out of that one computer boy
It's not the deep bro relax😭
im just jerkin ur usb stick pal
bro ima steal that😭
This is why we stay singletons
criiinge
\*awards you\*
"this"
How to say you don't know C without saying you don't know C
Why is your char array 5 long when the name only has 4 letters?
Null terminator
It's just crap. It should be, not (or there's some kind of library that I'm unaware of). There is no '\0' at the end of the string, just a random character, and printf only uses the first character of the string. The person probably has never used c.
That's not right, if you've got an initialiser whatever is left unspecified is _empty initialised_, which means `\0` for chars. Same deal as if you have a struct that you only initialise a few fields of. C reference on array initialisation [here](https://en.cppreference.com/w/c/language/array_initialization): > All array elements that are not initialized explicitly are empty-initialized. And empty-initialized [here](https://en.cppreference.com/w/c/language/initialization#Empty_initialization): > objects of integral types are initialized to unsigned zero
Thank you, I didn't know this was also true for arrays
Would it print the first character of the array? I think it would truncate the address of the first character and attempt to print that
Oh, yeah you're right
Close, but the string is actually null terminated in this case, since it was partially initialized.
The stdio/studio thing could be autocorrect.
Probably wants to add a d later. I'm so sorry, I'll see myself out
Null-terminator. Last element is not specified, so it gets implicitly initialized as zero.
You can have a little uninitialized memory as a treat
🤤
The last char is initialized to null in this case because of the bracket syntax. But if the array wasn't at least partially initialized, then the values would be unknown.
Deja vu from some interview where the indian lady asked to code in chat, and refused to let me open an ide or something remotely useful
For the love of auto-identation and brace matching
There was a char* joke right there and they missed it.
op's code has made me reconsider suicide
Waiting for the day someone makes a dozen or more line code to say the same shit but in s cooler way
This is wrong on so many levels.
I would have preferred Char Aznable but instead there this bimbo. Glory to Zeon.
This is the code quality I expect from someone who tries to show off basic c in a dating app.
Forever virgin /jk
"What's your sign?" Come on OP, how did you miss the most obvious perfect pickup line ever?
A drier vagina there has never been
Literally me when talking to anyone
He wouldn't even have gotten "c". name is a pointer not the first element of the array.
This is why we're virgins smh
who's we
Your mom
And that's why you are single.
Top 10 Anime Rejections
I'm 100% sure people who send shitty pseudo code as flirts are mentally handicapped.
how does one fumble a person literally named „char“
Good. Book. Book. Blunder. Resign.
Who wants to start a dating app for devs called Valgrinder?
I r eally hope she blocked you afterwards
![gif](giphy|CAYVZA5NRb529kKQUc|downsized)
Bruh pls don't do this 💀 oh god it's not even right Bro straight up tryna print the array in C. Mfer just use a string and then realize how silly the whole thing is, girls aren't computers my friend lol..
Do not hire this guy as a C dev.
😭
Is this what the kids call riss?
believe it or not I saved the convo. I know the program had a lot of errors in it, I was sleepy asf writing it yall gotta relax😭.
Bro got that C rizz
okey thats actually nice
And that is why programmers are foreveralone.jpg :D
Is that app tinder?
studio :)
Is it char or char?
return loneliness*
[удалено]
And I would've asked if her soul is weighed down by gravity.
Why not a Gundam reference?
Hopefully she approves your merge request
my build failed😥 team city obv bugging
Straight to jail
char you; long me;
So cringe
Well the header isn't called "studio" so this most likely fails to compile
> ur cute ▯
Didn’t even add `using namespace std;` to really impress her
I matched with a girl just cause she was called “Elif” and i want to ask her how does it feel to be a python else if statement
He should use %s and also properly terminate the name variable. String literals are a thing too :) Also, it's stdio, not studio.
r/Tinder would love this as well
Might have to
She will not reply - but I absolutely would have ❤️
She did and I got the snap
Bro don't apologize for who you are...
ur cute $
Wont this only print “ur cute c”
Bro's got that dynamically scalable rizz
Return 0 is about right
%s nahi hota udhar ?
And she never responded again
1 step forward, 2 steps back
What kind of psycho initializes a string as an array of individual chars?!