Hi I got confused to get the explanation for this below, can anyone explain it to me? Thanks in advance.
#include<stdio.h>
int main(){
char *arr,c;
arr = &c;
arr++;
*arr = 'a';
arr++;
*arr = 'b';
arr++;
*arr = 'c';
arr--;
arr--;
printf("\narr 1 = %c",arr);
printf("\narr 2 = %c",arr[1]);
printf("\narr 3 = %c",arr[2]);
getch();
return 1;
}
Output is :
arr 1 = a
arr 2 = b
arr 3 = c
but if the change the line:
printf("\narr 1 = %c",arr);
with
printf("\narr 1 = %c",arr[0]);
Now Output is:
arr 1 =
arr 2 = b
arr 3 = c
why 'a' is not getting printed.?
*For all those who are questioning the program as bad coding.. I know its not a good coding practice to use pointer like this, But my question is why arr[0] is not printing anything where as arr[1] & arr[2] is printing what is assigned?