Home>Article>Backend Development> Detailed explanation of C language structure

Detailed explanation of C language structure

Guanhui
Guanhui Original
2020-06-09 13:24:55 3030browse

Detailed explanation of C language structure

Detailed explanation of C language structure

C language structure is a constructed data type, which can also be called a complex data type. It consists of several It is composed of different types of variables. Each variable is a member of the structure. Each member can be a basic data type or a constructed type. It is similar to a class in object-oriented programming, except that there are no member methods.

Definition of structure type variables

There are three ways to define structure variables:

1. First declare the structure type, and then define the Type variable:

struct UDP_Server_Thread_Para { void *pData; int Len; }; UDP_Server_Thread_Para UDPThreadPara1,UDPThreadPara2;

In order to facilitate understanding, the struct UDP_Server_Thread_Para type can be analogized to the int type, UDP_Server_Thread_Para UDPThreadPara1, UDPThreadPara2 is int UDPThreadPara1, UDPThreadPara2.

2. Define variables while declaring:

struct UDP_Server_Thread_Para { void *pData; int Len; }UDPThreadPara1,UDPThreadPara2;

It is more intuitive to declare and define variables together, but you cannot redefine new structure variables in this way, and when comparing In large code projects, in order to make the program structure clear, type declarations and variable definitions are placed in different locations.

3. Directly define structure type variables without specifying a type name:

struct { void *pData; int Len; }UDPThreadPara1,UDPThreadPara2;

Recommended tutorials: "PHP" "C#"

The above is the detailed content of Detailed explanation of C language structure. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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