In the below piece of code, I am not able to change the values of x and y individually. Can some one help me with assigning these values individually?
#include <stdio.h>
struct p
{
int x;
int y;
};
int main()
{
int p2 = 55;
int p3 = 99;
//const struct p *ptr1 = {&p2,&p3}; --- giving the expected result
const struct p *ptr1;
ptr1->x = &p2; //error
ptr1->y = &p3; //error
printf("%d %d \n", ptr1->x, ptr1->y);
}
Note: I have searched for such an example, I could not able to find and I am running out of time. If the question is already asked, I am really very sorry to waste your time and please provide me the link for the same to refer.
p2andp3seem to get cast to an integer value? What is the expected result?const,unallocatedpointer for writing compiler does not perform implicit cast fromint *tointand write it silently.