
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.
立即学习“C语言免费学习笔记(深入)”;
Shell本身是一个用C语言编写的程序,它是用户使用Linux的桥梁。Shell既是一种命令语言,又是一种程序设计语言。作为命令语言,它交互式地解释和执行用户输入的命令;作为程序设计语言,它定义了各种变量和参数,并提供了许多在高级语言中才具有的控制结构,包括循环和分支。它虽然不是Linux系统核心的一部分,但它调用了系统核心的大部分功能来执行程序、建立文件并以并行的方式协调各个程序的运行。因此,对于用户来说,shell是最重要的实用程序,深入了解和熟练掌握shell的特性极其使用方法,是用好Linux系统
24
A structure can be declared as follows −
Struct structurename{
//member declaration
};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);
}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
以上就是在C语言中,结构变量的访问方式如下所述的详细内容,更多请关注php中文网其它相关文章!
C语言怎么学习?C语言怎么入门?C语言在哪学?C语言怎么学才快?不用担心,这里为大家提供了C语言速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号