Structure

Structure

Structure is a user define data-type in C language. Structure holds different type elements.

Each element of structure is called member.

struct is a keyword.

Syntax

struct structure_name{
data-type member-variable-1;
data-type member-variable-2;
data-type member-variable-3;
...........
...........
};

example:
struct student{
char stName[100];
char stMob[15];
char stAddress[300];
};

In above example "student" is the name of structure. stName, stMob, stAddress are member of structure.


Declaring Structure Variable

There are two ways to declare structure variable.
(1.) with structure body.
(2.) In main() function.


1st-way(with structure body)

Syntax

struct structure_name{
data-type member-variable-1;
data-type member-variable-2;
data-type member-variable-3;
...........
...........
}struct_variable1, sruct_variable2,......;

example:
struct student{
char stName[100];
char stMob[15];
char stAddress[300];
}st1,st2;

In above example st1 and st2 are structure type variable.


2nd-way(in main() function)

Syntax

struct structure-name variable;

example:
struct student st1,st2;


Accessing Member of Structure

There are two ways to access structure members:
(1)By . (member or dot operator)
(2)By -> (structure pointer operator)


See Output

See Output

About Us

Comsysapp.com is an educational website. Students and software developers can learn programming language tutorials. Comsysapp is very useful for beginners and professional developers. Comsysapp provides tutorial in easy language. Comsysapp.com has focus on simplicity.

Services

Comsysapp.com provides free tutorials like c, html, css, etc. All tutorials are free for beginner and professionals.


Terms of Use

comsysapp.com is not responsible for any mistake. We are not responsible if information made available on our website is incomplete or invalid. But comsysapp.com always try for zero-zero mistake.

Privacy policy

comsysapp.com does not collect any data from users. We use Google AdSense advertising on our website. We never ask personal or private information.


Sitemap

sitemap

copyright © 2023