V
vjay
Check the code below guys
void main()
{
char a[5] = {1,2,3,4,5};
char *ptr;
ptr = (char*)(&a + 1);
printf("%d",*(ptr-1));
}
The output of the program is 5
But what i expected was 1.When i replace &a with a in the expression ptr =
(char*)(a + 1); i get output as 1.what is the difference between (&a + 1)
and (a + 1) in the above mentioned expression.Help guys its confusing.
void main()
{
char a[5] = {1,2,3,4,5};
char *ptr;
ptr = (char*)(&a + 1);
printf("%d",*(ptr-1));
}
The output of the program is 5
But what i expected was 1.When i replace &a with a in the expression ptr =
(char*)(a + 1); i get output as 1.what is the difference between (&a + 1)
and (a + 1) in the above mentioned expression.Help guys its confusing.