Code:
#include<stdio.h>
int main(void)
{
int *p="Hello_i_am_abhijeet"; //Whats this actually doing???
char q[]="Hello_i_am_abhijeet"; //This is OK
printf("%c %c\n",p[2],q[2]); //Here p[2] shows "a" that means
//due to p[2], pointer moves 8 bytes
return 0;
}
codefire@codefi re-desktop:~$ gcc test.c
test.c: In function ‘main’:
test.c:4: warning: initialization from incompatible pointer type
codefire@codefi re-desktop:~$ ./a.out
a l
codefire@codefi re-desktop:~$
I want to know as to what actually happens in line 4 of program.
I know line 4 may look weird.
But, i was curious to know. And hows is the output coming, i mean whats theory behind that.
Also, it would be great if you pls help me understanding the difference between "char *a" and "char a[]". I tried searching on net but couldnt get satisfied with what i understood.
Your reply will be of great help to me.
Comment