#include <stdio.h>
int main(void)
{
// your code goes here
char *s = "Hello world!";
printf("%d\n", sizeof(s=s+2));
printf("%d\n", sizeof(++s));
printf("%s\n",s);
printf("%s\n",s=s+3);
printf("%s\n",s++);
printf("%s\n",++s);
printf("%s\n",s++);
printf("%s\n",s++);
printf("%s\n",s++);
printf("%s\n",s++);
return 0;
}
I know sizeof() operator takes operand as input(unary operator) and prints it's size.For eg. in case of pointers, it prints it's size say 4(based on machine),for data type it's respected size and so on for structure and union operands.But in above code sizeof(s++)
and sizeof(s=s+2)
isn't working as i expected.I thought next printf("%s",s)
would print the given string after skipping few characters but it didn't. Isn't s incremented inside whensizeof(s=s+2)
like in the later printf("%s",++s)
statements.
Output
8
8
Hello world!
lo world!
lo world!
world!
world!
world!
orld!
rld!
What is wrong with this?