How can I dereference the pointer as i pack the structure in fill function and pass the pointer to send how to dereference it? as i get segmentation fault in what i have done
#include<stdio.h>
struct xxx
{
int x;
int y;
};
void fill(struct xxx *create)
{
create->x = 10;
create->y = 20;
send(*create);
}
main()
{
struct xxx create;
fill(&create);
}
send(struct xxx *ptr)
{
printf("%d\n",ptr->x);
printf("%d\n", ptr->y);
}
send(*create) will send the actual struct object, not a pointer.
send(create) will send the pointer, which is what you need.
When your function declaration's arguments contain an asterisk (*), a pointer to something is needed. When you then pass that argument on to another function requiring another pointer, you need to pass the name of the argument, since it is already a pointer.
When you used the asterisk, you dereferenced the pointer. That actually sent the "cell of memory that create points to," the actual struct and not a pointer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With