I am not able to understand the output of the following C code :
#include
main()
{
char * something = \"something\";
printf(\"%c\", *someth
It is pretty simple.
char * something = "something";
Assignment of pointer.
printf("%c\n", *something++);//equivalent to *(something++)
Pointer is incremented but the value before increment is dereferenced ans it is post-increment.
printf("%c\n", *something);//equivalent to *(something)
Pointer is now pointing to 'o' after increment in the previous statement.
printf("%c\n", *++something);//equivalent to *(++something)
Pointer is incremented to point to 'm' and dereferenced after incrementing the pointer as this is pre-increment.
printf("%c\n", *something++);//equivalent to *(something++)
Same as the first answer.
Also notice '\n'
at the end of every string in printf. It makes the output buffer flush and makes the line print. Always use a \n
at the end of your printf.
You may want to look at this question as well.