What is the output of this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the output of this code?

int i=0; printf("%d"+1,i); explain it plsss

27th Feb 2017, 3:48 PM
Upendar Chinna
Upendar Chinna - avatar
7 Answers
0
01 ***I believe. going from java.... the %d is the parameter, that you put in. so it will first substitute that value there then the + 1, concatenates a 1 to whatever it was. so if you got string x = "the"; printf("%s" + 3, x); you should see the3 hope im right lol. hope this helps!!
28th Feb 2017, 6:52 AM
Michael Szczepanski
Michael Szczepanski - avatar
0
i am getting the output as d but why
28th Feb 2017, 7:46 AM
Upendar Chinna
Upendar Chinna - avatar
0
d is a placeholder for an integer parameter, I, which will be substituted in at runtime. if you are getting the character d to print out. your compiler is broken.
28th Feb 2017, 4:54 PM
Michael Szczepanski
Michael Szczepanski - avatar
0
yeah I got it printf("hello"+2); outputs llo printf("godaddy"+2);. outputs daddy similarly printf("%d"+1,i);. outputs d ..... it's a different concept!!!!
28th Feb 2017, 4:57 PM
Upendar Chinna
Upendar Chinna - avatar
0
it takes off the first two letters of the string????? what?. that means that it wouldn't print anything out. unless it sees the % as a printable character. then you would only get d. but that completely deteriorated the point of the printf function...
28th Feb 2017, 5:09 PM
Michael Szczepanski
Michael Szczepanski - avatar
0
Yeah , right , I said it is a new concept.....try it in compiler.....
28th Feb 2017, 6:33 PM
Upendar Chinna
Upendar Chinna - avatar
0
oh. I have never used c.............. lol
28th Feb 2017, 7:07 PM
Michael Szczepanski
Michael Szczepanski - avatar