EmbLogic's Blog

Different ways to make and use the structures in C language.

#include<stdio.h>
2
3
4         struct
5         {
6                 char a;
7                 int b;
8                 int c;
9         }d;//as d is the variable of the structure and this is the structure without its name that’s why we can’t make the further     variable in the main i.e struct<struct name> z is not possible;
10
11         struct abc//name of the structure
12         {
13                 char p;
14                 int q;
15                 int r;
16         }s;//variable of the structure abc and we can make the further variables as struct abc z

18         typedef struct
19         {
20                 char p;
21                 int q;
22                 int r;
23         }a;//its the not the variable its the name of the structure which is typeddef as a new datatype is “a”
24
25 int main()
26 {/************print the same the i.e the size of the structure****************/
27         printf(“size of the first structure is %d\n”,sizeof(d));
28         printf(“size of the second structure is %d\n”,sizeof(struct abc));
29         printf(“size of the third structure is %d\n”,sizeof(a));
30 }

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>