+ 2
What will be the output of the following program and please explain it ?
#include<stdio.h> void main() { char s[]="hello"; printf("%c\n",*(s+1)); printf("%c\n",*s+1); printf("%s\n",*(s+1)); }
5 odpowiedzi
+ 3
Have you tried compiling it?
Take a look, I've commented it for you: https://code.sololearn.com/cmw8om2I5PK1/?ref=app
There is a whole lesson on pointers in Sololearn's C course, take a look: https://www.sololearn.com/learn/C/2962/
+ 3
I have updated the code. You use %s to print string. Pointer points to one element only (the element of a string is char) , therefore use %c.
+ 2
In your code you have written %c at last statement that's why it shows answer but if
You replace it by %s then it shows no output
Tell me why is is so?
+ 1
*(s+1) is more like s[1] that is e.
2nd *s+1 is more like s[0]+1 and s[0] is h and when you add 1 to h it will give you the next alphabet after h that is i.
3rd one is you are trying to print a string %s and in *(s+1) i.e s[1]= e that is just a character not string so it will not print any thing i hope you get it
0
Here in this program even " are also character values. Then why don't s(0) value as " .