pointer to structure in c
I have written code to understand pointer to structure
Code:
#include<stdio.h>
#include<stdlib.h>
struct point //define structure
{
int x; //structure member type integer
char y; // structure member type charactr
};
void main ()
{
struct point *p = NULL; // p is pointer to structure variable and the value stored in pointer is NULL
p = malloc(sizeof(*p)); // Allocate dyanamic memory for pointer to structure variable p
p->x = 8; // p is pointer to structure pointing to variable x that is integer type and value store in x is 8
p->y = 'A'; // p is pointer to structure pointing to variable y that is char type and value store in y is 'A'
}
I have doubt, do my last two comments match with the code lines ?
if not so what should i write in comments
Code:
p->x = 8; // p is pointer to structure pointing to variable x that is integer type and value stored in x is 8
p->y = 'A'; // p is pointer to structure pointing to variable y that is char type and value stored in y is 'A'
If not what should i write in comments