1#include<stdio.h>
2#include<string.h>
3
4struct Student{
5long int rollNo;
6int age;
7char name[50];
8int totalMarks;
9};
10
11int main(){
12
13 struct Student s1;
14 //accessing members of the struct
15 s1.rollNo = 1232234643;
16 s1.age = 10;
17 char s[]="Jonathan";
18 strcpy(s1.name,s);
19 s1.totalMarks = 450;
20
21 printf("RollNumber: %d \nName: %s \nTotal Marks: %d",s1.rollNo,s1.name,s1.totalMarks);
22
23return 0;
24}
25
1#include <stdio.h>
2#include <stdlib.h>
3
4struct book{ //this is like making a datatype of type book
5 //these are the fields
6 char name[50];
7 char author[50];
8 char ISBN[11];
9};
10
11int main(){
12 struct book book1; //making an instance of book called book1
13 /*
14 normally to store integers in a struct we can do something like
15 book1.number_of_pages = 22; which is correct
16 however with character arrays we need to use the strcpy
17 function
18 */
19
20 strcpy(book1.name, "james and the giant tatti");
21 strcpy(book1.author, "Krishan Grewal");
22 strcpy(book1.ISBN, "12345678987");
23
24 printf("book name: %s\n", book1.name);
25 printf("book author: %s\n", book1.author);
26 printf("book ISBN: %s\n", book1.ISBN);
27
28return 0;
29}
1struct [structure_tag]
2{
3 //member variable 1
4 //member variable 2
5 //member variable 3
6 ...
7}[structure_variables];
8
1// dichiarazione della struct
2struct libro
3{
4 char titolo[100];
5 char autore[50];
6 int anno_pubblicazione;
7 float prezzo;
8};
9
10//dichiarazione dell'istanza biblio
11struct libro biblio;
12