computer

If int main() { int a=1; int *p; how do the following statements differ 1) p=&a; 2) *p=&a; 3) p=a; 4) printf("%d",p); 5) printf("%d",*p); and what does int **a mean

Answers

The statement 1) p=&a; assigns the memory address of the variable a to the pointer *p. The statement 2) *p=&a; is invalid syntax, since *p is a pointer, not a memory address. The statement 3) p=a; assigns the value of a to the pointer p. The statement 4) printf("%d",p); prints out the memory address stored in the pointer p. The statement 5) printf("%d",*p); prints out the value stored in the memory address pointed to by the pointer p. int **a means that a is a pointer to a pointer to an int. This means that a contains the memory address of a pointer to an int. The value stored in the memory address stored in a can be accessed by dereferencing twice (*a and **a).

Answered by Jeanne

We have mentors from

Contact support