Code:
struct s
{ int a; };
int main()
{
struct s my_s;
struct s *sp;
sp = &my_s;
(*sp).a; // is the same thing as
sp->a;
return 0;
}
Code:
#include <stdio.h>
char doug[] = "Doug";
struct structure
{
char* name;
}*struct_ptr;
int main()
{
struct_ptr->name = &doug[0]; // struct_ptr is not pointing to anything in particular.
printf("%s",*struct_ptr->name); // use "printf("%s", struct_ptr->name);". -> already dereferences struct_ptr.
return 0;
}
Code:
#include <stdio.h>
char doug[] = "Doug";
struct structure
{
char* name;
} *struct_ptr;
int main()
{
struct structure sinstance; // something for struct_ptr to point to
struct_ptr = &sinstance;
struct_ptr->name = doug; // doug means the same thing as &doug[0]. sinstance.name now equals "Doug".
printf("%s",struct_ptr->name);
return 0;
}