Home > Backend Development > C#.Net Tutorial > What are the reserved words for defining structures in C language?

What are the reserved words for defining structures in C language?

烟雨青岚
Release: 2020-07-02 17:28:35
Original
8729 people have browsed it

The reserved word for defining structures in the C language is "struct". The struct in C language is a user-defined data type. It does not have permission to set. It can only be a collection of variables. Although it can encapsulate data, it cannot hide data, and its members cannot be functions.

What are the reserved words for defining structures in C language?

struct is used in C language to define a series of data collections composed of the same type or different types of data, also called a structure.

The struct in C language is a user-defined data type (User Defined Type). It does not have permission to set. It can only be a collection of some variables. Although it can encapsulate data, it cannot Hide data, and members cannot be functions.

The usage of struct is the same as using int to define integer variables. struck is the structure variable to be declared at the beginning of program editing.

For example, if you want to edit a program to specifically filter and output a group of students, you need to define a structure variable that includes the student code, student name, student age and student gender, and then you can perform computer screening on this group of students. . As shown below:

What are the reserved words for defining structures in C language?

Extended information:

In practical problems, a set of data often has different data types. For example, in the student registration form, the name should be of character type; the student number can be of integer or character type; the age should be of integer type; the gender should be of character type; and the grades can be of integer or real type.

Obviously you cannot use an array to store this set of data. Because the type and length of each element in the array must be consistent to facilitate processing by the compilation system. In order to solve this problem, another structural data type - "structure" is given in the C language. It is equivalent to records in other high-level languages.

The general form of defining a structure is:

struct structure name{//member table column};

The member table is composed of several members, each member is an integral part of the structure. A type description must also be made for each member, in the form: type specifier member name; the naming of member names should comply with the writing regulations of identifiers.

For example: struct stu

{ int num;char name[20]; char sex; float score;};
Copy after login

In this structure definition, the structure is named stu, and the structure consists of 4 members.

The first member is num, an integer variable;

The second member is name, a character array;

The third member is sex, a character variable ;

The fourth member is score, a floating-point variable. Note that the semicolon after the parentheses is essential.

It is worth mentioning that in C, the function of struct has been strengthened. struct can not only add member variables, but also member functions, similar to class.

Recommended tutorial: "C Language"

The above is the detailed content of What are the reserved words for defining structures in C language?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template