
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Explain the accessing of structure variable in C language
The structure is a user-defined data type, which is used to store a collection of different data types of data.
The structure is similar to an array. The only difference is that an array is used to store the same data types whereas, the structure is used to store different data types.
The keyword struct is for declaring the structure.
Variables inside the structure are the members of the structure.
A structure can be declared as follows −
Struct structurename{ //member declaration };
Example
Following is the C program for accessing a structure variable −
struct book{ int pages; float price; char author[20]; }; Accessing structure members in C #include<stdio.h> //Declaring structure// struct{ char name[50]; int roll; float percentage; char grade[50]; }s1,s2; void main(){ //Reading User I/p// printf("enter Name of 1st student : "); gets(s1.name); printf("enter Roll number of 1st student : "); scanf("%d",&s1.roll); printf("Enter the average of 1st student : "); scanf("%f",&s1.percentage); printf("Enter grade status of 1st student : "); scanf("%s",s1.grade); //Printing O/p// printf("The name of 1st student is : %s
",s1.name); printf("The roll number of 1st student is : %d
",s1.roll); printf("The average of 1st student is : %f
",s1.percentage); printf("The student 1 grade is : %s and percentage of %f
",s1.grade,s1.percentage); }
Output
When the above program is executed, it produces the following result −
enter Name of 1st student: Bhanu enter Roll number of 1st student: 2 Enter the average of 1st student: 68 Enter grade status of 1st student: A The name of 1st student is: Bhanu The roll number of 1st student is: 2 The average of 1st student is: 68.000000 The student 1 grade is: A and percentage of 68.000000
- Related Articles
- Explain the concept of pointer accessing in C language
- Explain the Random accessing files in C language
- Explain the concept of Uninitialized array accessing in C language
- Explain scope of a variable in C language.
- Explain Lifetime of a variable in C language.
- Explain Binding of a variable in C language.
- Explain linear data structure queue in C language
- Explain variable declaration and rules of variables in C language
- Explain the dynamic memory allocation of pointer to structure in C language
- Explain the variable declaration, initialization and assignment in C language
- Explain bit field in C language by using structure concept
- Explain top-down design and structure chart of function in C language
- Structure declaration in C language
- What is union of structure in C language?
- Explain the history of C language?

Advertisements