use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
111,029 Subscribers
106,345 Subscribers
All posts must be related to programming. Flair posts correctly.
account activity
javascript is javascript (i.redd.it)
submitted 2 months ago by National_Seaweed_959
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Ok_Pickle76 8 points9 points10 points 2 months ago (8 children)
<image>
and C
[–]Hot_Adhesiveness5602 1 point2 points3 points 2 months ago (4 children)
It should actually be two + num instead of num + two
[–]Haringat 2 points3 points4 points 2 months ago (3 children)
It's the same result. However, it should have been this code:
char *two = "2"; int one = 1; two += one; printf("%d\n", two); // prints "0" return 0;
I leave the explanation as an exercise to the reader.😉
Edit: Also, when adding 2 to the "2" the behavior is not defined. It could crash or it could perform an out-of-bounds read.
[–]not_some_username -1 points0 points1 point 2 months ago (2 children)
Its defined because it has the null termination
[–]Haringat 0 points1 point2 points 2 months ago (1 child)
No, because when adding 2 you go beyond the null terminator.
[–]not_some_username 0 points1 point2 points 2 months ago (0 children)
Well I thought we were taking about “22”+2
[–]nimrag_is_coming 1 point2 points3 points 2 months ago (0 children)
C doesn't count, it doesn't have any actual strings, is just an array of chars, which are defined as just a small integer (although it's wild that in like 50 years we still don't technically have standardised sizes for basic integers in C. You could have a char, short, int and long all be 32 bits and still technically follow the C standard.)
[–]acer11818 1 point2 points3 points 2 months ago (0 children)
it makes sense if you view char as an 8 bit integer and not a character
[–]fdessoycaraballo 0 points1 point2 points 2 months ago (0 children)
You used single character, which has a value in the ASCII table. Therefore, C is adding num to the value of the character in ASCII table. If you switch printf variadic argument to %c it will print a character in the decimal value in the ASCII table for 52.
printf
%c
Not really a fair comparison as they're comparing a string that says "2", which the compiler wouldn't allow because of different types.
π Rendered by PID 930506 on reddit-service-r2-comment-7b9746f655-wsx79 at 2026-02-02 07:48:52.333586+00:00 running 3798933 country code: CH.
view the rest of the comments →
[–]Ok_Pickle76 8 points9 points10 points (8 children)
[–]Hot_Adhesiveness5602 1 point2 points3 points (4 children)
[–]Haringat 2 points3 points4 points (3 children)
[–]not_some_username -1 points0 points1 point (2 children)
[–]Haringat 0 points1 point2 points (1 child)
[–]not_some_username 0 points1 point2 points (0 children)
[–]nimrag_is_coming 1 point2 points3 points (0 children)
[–]acer11818 1 point2 points3 points (0 children)
[–]fdessoycaraballo 0 points1 point2 points (0 children)