I try to understand what value we get when dereference the pointer to struct.
My struct is.
struct car
{
int a = 5;
int b = 10;
int c = 2;
int d = 14;
int e = 20;
};
My code in main function is
int main()
{
car k1,k2,k3,k4,k5; // declare struct variable
car* ptr1,*ptr2,*ptr3,*ptr4,*ptr5;// declare pointer to struct variable
ptr1 = &k1;
ptr2 = &k2;
ptr3 = &k3;
ptr4 = &k4;
ptr5 = &k5;
printf("*ptr1=%d *ptr2=%d *ptr3=%d *ptr4=%d *ptr5=%d \n", *ptr1,*ptr2,*ptr3,*ptr4,*ptr5);
};
When I dereference ptr1 to ptr5.I get the value correspond with the value of member in struct(value a to e).Why I get this value.