what is structure in c laguage with codeinc2 ?
STRUCTURE-: structure is a way to group variables.
-: structure is a collection of dissimilar elements.
-: defining structure means creating new data type.
array is a collection of same type of elements but in many real life applications we may need to group different types of logically related data.
example-; if we want to create a record of a person that contains name, age, and height of that person, we can't use array because all the three data elements are of different types.to store these related fields of different data types we can rse a structure, which is capable of storing heterogeneous data. data of different types can be grouped together under a single name using structures. the data elements of a structure are referred to as members.
Declaring a structure type-;
all the variables that would be declared of this structure type, the general syntax of a structure declaration is-
Declaration of a structure provides one more data type in addition to the built in data types. we can declare variables of this new data type that will have the fornat of the declared structure.
let us take an example of declaring a structure template
struct student
{
char name[20];
int rollno;
float marks;
};
Here student is the structure tag and there are three members of this structure viz. name, rollno and marks. structure template can be declared globally or locally.
Using Structure tag
we can also declare structure variables using structure tag, This can be written as-
struct student
{
char name[20];
int rollno;
float marks;
};
Here stu1, stu2 and stu3 are structure variables that are declared using the structure tag student.
Follow me on instagram and discuss anything about 'C' language-:
https://www.instagram.com/raushan.nit33/
Visit my profile-
STRUCTURE-: structure is a way to group variables.
-: structure is a collection of dissimilar elements.
-: defining structure means creating new data type.
array is a collection of same type of elements but in many real life applications we may need to group different types of logically related data.
example-; if we want to create a record of a person that contains name, age, and height of that person, we can't use array because all the three data elements are of different types.to store these related fields of different data types we can rse a structure, which is capable of storing heterogeneous data. data of different types can be grouped together under a single name using structures. the data elements of a structure are referred to as members.
Declaring a structure type-;
all the variables that would be declared of this structure type, the general syntax of a structure declaration is-
struct [structure_tag]
{
//member variable 1
//member variable 2
//member variable 3
...
}[structure_variables];
Declaration of a structure provides one more data type in addition to the built in data types. we can declare variables of this new data type that will have the fornat of the declared structure.
let us take an example of declaring a structure template
struct student
{
char name[20];
int rollno;
float marks;
};
Here student is the structure tag and there are three members of this structure viz. name, rollno and marks. structure template can be declared globally or locally.
Using Structure tag
we can also declare structure variables using structure tag, This can be written as-
struct student
{
char name[20];
int rollno;
float marks;
};
struct student stu1, stu2;struct student stu3;
Here stu1, stu2 and stu3 are structure variables that are declared using the structure tag student.
Follow me on instagram and discuss anything about 'C' language-:
https://www.instagram.com/raushan.nit33/
Visit my profile-
Comments
Post a Comment