+ 1
Hello guys there's a question in my mind.
Whats the difference btw int * ptr = a; and int * ptr = &a; And also difference btw printf("%x",*ptr); , printf("%x",ptr); and Printf("%x", *(ptr));
1 Réponse
+ 2
*ptr is a pointer variable. It is used to store the address of another variable.
int *ptr = &a; // this will store the address of a in the pointer variable.
int *ptr = a; // this will throw error since we are trying to assign int value to a pointer. It's like assigning a char value to an integer.
printf("%x",*ptr); // this will print the value of address stored in the pointer. So it will print the value of a.
printf("%x",*(ptr)); // this is similar to *ptr.
printf("%x",ptr); // this will print the address of a. This is the value stored in the pointer variable.