I am trying to modify value of structure via function call. I don't understand how to do it in function
I am passing address of structure to function
Code:
#include<stdio.h>
#include<stdlib.h>
struct node
{
int x ;
char y;
};
void modify( struct node **dsptr)
{
printf(" dsptr store at location : %p \n", &dsptr);
printf(" value of dsptr = %p \n", dsptr);
printf(" %p \n", *dsptr);
printf(" %p \n", **dsptr);
}
int main(void)
{
struct node *sptr = malloc (sizeof(struct node));
printf(" sptr store at location : %p \n", &sptr);
printf(" value of sptr = %p \n", sptr);
sptr -> x = 1;
sptr -> y = 'A';
printf(" value of first object of structure = %d \n", sptr -> x);
printf(" value of second object of structure = %c \n", sptr -> y);
modify(&sptr);
return 0;
}
Output
Code:
sptr store at location : 0061FF1C value of sptr = 009F1598
value of first object of structure = 1
value of second object of structure = A
dsptr store at location : 0061FF00
value of dsptr = 0061FF1C
009F1598
00000001