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 −
Live Demo
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</p><p>",s1.name); printf("The roll number of 1st student is : %d</p><p>",s1.roll); printf("The average of 1st student is : %f</p><p>",s1.percentage); printf("The student 1 grade is : %s and percentage of %f</p><p>",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
The above is the detailed content of In C language, structure variables are accessed as follows. For more information, please follow other related articles on the PHP Chinese website!

This article explains the C Standard Template Library (STL), focusing on its core components: containers, iterators, algorithms, and functors. It details how these interact to enable generic programming, improving code efficiency and readability t

This article details efficient STL algorithm usage in C . It emphasizes data structure choice (vectors vs. lists), algorithm complexity analysis (e.g., std::sort vs. std::partial_sort), iterator usage, and parallel execution. Common pitfalls like

The article discusses dynamic dispatch in C , its performance costs, and optimization strategies. It highlights scenarios where dynamic dispatch impacts performance and compares it with static dispatch, emphasizing trade-offs between performance and

C 20 ranges enhance data manipulation with expressiveness, composability, and efficiency. They simplify complex transformations and integrate into existing codebases for better performance and maintainability.

This article details effective exception handling in C , covering try, catch, and throw mechanics. It emphasizes best practices like RAII, avoiding unnecessary catch blocks, and logging exceptions for robust code. The article also addresses perf

The article discusses using move semantics in C to enhance performance by avoiding unnecessary copying. It covers implementing move constructors and assignment operators, using std::move, and identifies key scenarios and pitfalls for effective appl

Article discusses effective use of rvalue references in C for move semantics, perfect forwarding, and resource management, highlighting best practices and performance improvements.(159 characters)

C memory management uses new, delete, and smart pointers. The article discusses manual vs. automated management and how smart pointers prevent memory leaks.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.
