Structure Variable Declaration
1. With structure definition
Syntax:
struct tagname
{
datatype member1;
datatype member2;
:
:
datatype memberN;
} var1, var2, var3 ;
Example:
struct student
{
char name[20];
char usn[20];
int age;
float mark;
} S1, S2, S3;
---------------------------------------------------------------------------------------------------------------------
2. Omitting tagname
Syntax:
struct
{
datatype member1;
datatype member2;
:
:
datatype memberN;
} var1, var2, var3 ;
Example:
struct
{
char name[20];
char usn[20];
int age;
float mark;
}S1, S2, S3;
---------------------------------------------------------------------------------------------------------------------
3. Using struct tagname
Syntax:
struct tagname
{
datatype member1;
datatype member2;
:
:
datatype memberN;
};
struct tagname var1, var2, var3 ;
Example:
struct student
{
char name[20];
char usn[20];
int age;
float mark;
};
struct student S1, S2, S3;
---------------------------------------------------------------------------------------------------------------------
4. Using typedef
Syntax:
struct tagname
{
datatype member1;
datatype member2;
:
:
datatype memberN;
};
typedef struct tagname newname;
newname var1, var2, var3 ;
Example:
struct student
{
char name[20];
char usn[20];
int age;
float mark;
};
typedef struct student stu;
stu S1, S2, S3;
---------------------------------------------------------------------------------------------------------------------
5. Using typedef struct tagname
Syntax:
typedef struct tagname
{
datatype member1;
datatype member2;
:
:
datatype memberN;
}newname;
newname var1, var2, var3 ;
Example:
typedef struct student
{
char name[20];
char usn[20];
int age;
float mark;
}stu;
stu S1, S2, S3;
---------------------------------------------------------------------------------------------------------------------
6. Using typedef struct
Syntax:
typedef struct
{
datatype member1;
datatype member2;
:
:
datatype memberN;
}newname;
newname var1, var2, var3 ;
Example:
typedef struct
{
char name[20];
char usn[20];
int age;
float mark;
}stu;
stu S1, S2, S3;
---------------------------------------------------------------------------------------------------------------------
7. Using typedef struct tagname (omiting newname)
Syntax:
typedef struct tagname
{
datatype member1;
datatype member2;
:
:
datatype memberN;
};
tagname var1, var2, var3 ;
Example:
typedef struct student
{
char name[20];
char usn[20];
int age;
float mark;
};
student S1, S2, S3;
---------------------------------------------------------------------------------------------------------------------
-->Check Next Topic-->
https://tejaswinihbhat.blogspot.in/2016/07/initialization-of-structure-variables.html
Goto Main Content:
https://tejaswinihbhat.blogspot.in/2016/07/data-structures-15CS33-Module1.html
https://tejaswinihbhat.blogspot.in/2016/07/structures.html
No comments:
Post a Comment