#include<stdio.h>
int main()
{
char *p = NULL;
char str[] = "How do you do!!!!!";
p = &str;
printf("String is:%s",p);
p = "HELLO HOW ARE YOU";
printf("String is:%s",p);
printf("Hello");
int a = 10;
int *pa;
pa = &a;
printf("Contents of a is %d\n",a);
printf("Contents of pa is %x\n", (int)pa);
printf("Values of variable pointed to by pa is %d\n", *pa);
return 0;
}
While referring to the above code :
p = &str;
printf("String is:%s",p);
p will display string stored.
pa = &a;
printf("Values of variable pointed to by pa is %d\n", *pa);
But here if i want to display value of a=10
I will have to write *pa
.
Why so ? What's the difference between the two ?
Why one show right when used p
and other will show right when used *pa
In one case derefernce operator is used and in other it is not required