Structure in C

It is user defined data type which is collection of data having different data types.

Declaration of structure

struct Person{
char name[100];
int age;
};

Create object of structure

struct Person p;

Access property of structure

p.name="aman"

Example

#include <stdio.h>
struct Person{
  char name[100];
  int age;
};
int main() {
  struct Person p;
  printf("Enter your name?");
  gets(p.name);
  
  printf("Enter your age?");
  scanf("%d", &p.age);
  
  printf("Your details is:\n");
  printf("Name:");
  puts(p.name);
  printf("Age:%d", p.age);
    
  return 0;
}
© 2016 - 2022, All Rights are Reserved.