Originally Posted by
abhi143
I am trying to verify that the address of variable and pointer value is same.
They are the same by definition: the address-of operator & results in a pointer to the operand.
If you really must, you can do the rather pointless exercise of:
Code:
#include <stdio.h>
struct player {
int number;
int rank;
};
int main()
{
struct player variable = {35, 1};
struct player *ptr = &variable;
int *number_ptr = &ptr->number;
int *rank_ptr = &ptr->rank;
printf("Memory Location of NUMBER: %p\n", (void*)&variable.number);
printf("Memory Location of RANK: %p\n", (void*)&variable.rank);
printf("Memory Location of NUMBER by pointer: %p\n", (void*)number_ptr);
printf("Memory Location of RANK by pointer: %p\n", (void*)rank_ptr);
printf("NUMBER: %d\n", ptr->number);
printf("RANK: %d\n", ptr->rank);
printf("NUMBER: %d\n", (*ptr).number);
printf("RANK: %d \n", (*ptr).rank);
return 0;
}