1// exemple avec la structure Coordonnees :
2struct Coordonnees
3{
4 int x;
5 int y;
6}
7
8int main()
9{
10 Coordonnees coords = {1,2};
11}
1struct address {
2 int street_no;
3 char *street_name;
4 char *city;
5 char *prov;
6 char *postal_code;
7};
8
9address temp_address = {
10 0, // street_no
11 nullptr, // street_name
12 "Hamilton", // city
13 "Ontario", // prov
14 nullptr, // postal_code
15};
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}
1typedef struct MY_TYPE {
2 bool flag;
3 short int value;
4 double stuff;
5} MY_TYPE;
6
7void function(void) {
8 MY_TYPE a;
9 ...
10 a = { true, 15, 0.123 }
11}
1struct Person
2{
3 char name[50];
4 int citNo;
5 float salary;
6} person1, person2, p[20];
7