Table of Contents
In this tutorial, we will discuss the Structure in C programming languages
the structure is a collection of different type of variables under a single name or unit. Which are grouped together and each element is called member in C programming Language
The structure is a user define or custom data type. Which contains an individual element that can defer in type. that allows to combine data items of a different kind Hence structure can contain integer, float, double etc.
define a structure
When defining a structure, you must use the struct statement or keyword in C to the grouped mixed type of variables
Access a structure
To access any member of s structure, we use the dot(.) member access operator. This operator pointed between the structure variable name and the structure member
Syntex
struct structure_name
{
data_type variable_name1;
data_type variable_name 2;
.................
.................
data_type variable_name n;
};
struct student
{
char name[50];
int age;
float fees;
}; when a struct variable is declared, storage is not allocated in the memory. if we want to work with the structure variable we must create the structure variable
method 1
create structure variable seperately
struct student
{
char name[50];
int age;
float fees;
}
int main(){
struct student stu1,stu2,p[30];
} create structure variable structure definition
struct student
{
char name[50];
int age;
float fees;
}struct student stu1,stu2;
printf|(s1.variable_name_1); printf|(s1.variable_name_2); ........... ........... printf|(s1.variable_name_n);
example – we want to store some information about a student, Student name, Student id, marks and garde We can easily create different variables name, stu.id, marks, age to store this information
Program 1
Similar post
Multiply two numbers in Java using scanner| 5 different ways In this article, we will…
5 Different ways to Divide two numbers in Java using scanner In this article, we…
Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…
10 ways to subtract two numbers in Java In this article, we will discuss the…
Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…
How to Divide two numbers in Java| 5 different ways In this article, we will…
This website uses cookies.