C Structs and Pointers (With Examples)
C Structs and Pointers (With Examples)
com
4 minutes
Before you learn about how pointers can be used with structs, be
sure to check these tutorials:
• C Pointers
• C struct
C Pointers to struct
struct name {
member1;
member2;
.
.
};
int main()
{
struct name *ptr, Harry;
}
int main()
{
struct person *personPtr, person1;
personPtr = &person1;
printf("Displaying:\n");
printf("Age: %d\n", personPtr->age);
printf("weight: %f", personPtr->weight);
return 0;
}
By the way,
#include <stdio.h>
#include <stdlib.h>
struct person {
int age;
float weight;
char name[30];
};
int main()
{
struct person *ptr;
int i, n;
return 0;
}