struct in c example
Example 1: struct in c
typedef struct {
char cognome[30];
char nome[20];
int voto;
}alunno;
Example 2: structs in c
#include <stdio.h>
#include <stdlib.h>
struct book{
char name[50];
char author[50];
char ISBN[11];
};
int main(){
struct book book1;
strcpy(book1.name, "james and the giant tatti");
strcpy(book1.author, "Krishan Grewal");
strcpy(book1.ISBN, "12345678987");
printf("book name: %s\n", book1.name);
printf("book author: %s\n", book1.author);
printf("book ISBN: %s\n", book1.ISBN);
return 0;
}
Example 3: declare structure in c
struct num{
int a ;
int b;
};
int main()
{
struct num n;
n.a=10;
n.b=20;
}
Example 4: Structure of Structs in c
The basic structure
Example 5: Structure of Structs in c
struct [structure_tag]
{
...
}[structure_variables];