I am new to C and I would like to know the difference between the below two snippet codes.When I try executing first one it works fine,but when I run the second one it gives me segmentation fault.Whats the reason for this behavior?
printf("%c\n",*strptr++);
printf("%c\n",*(strptr+i));
Here is the below code.
#include<stdio.h>
int main(void)
{
char str[100]="My name is Vutukuri";
int i=0;
char *strptr;
strptr=str;
while(*strptr != '\0')
{
printf("%c\n",*strptr++);
//printf("%c\n",*(strptr+i));
//i++;
}
return 0;
}
Entirely different.
The first snippet prints the character at
strptrand then incrementsstrptrby one.The second snippet prints the character at
strptr + i.