Home >Common Problem >What memory is allocated to a structure variable by the system when it is defined?

What memory is allocated to a structure variable by the system when it is defined?

藏色散人
藏色散人Original
2021-01-25 11:16:0918170browse

When defining a structure variable, the memory allocated to it by the system is the sum of the memory required by each member; the memory length occupied by the structure variable is the sum of the memory lengths occupied by each member; each member is separately Occupies its own memory unit, and the memory length occupied by the union variable is equal to the length of the longest member.

What memory is allocated to a structure variable by the system when it is defined?

The operating environment of this article: windows7 system, DELL G3 computer, C.

Recommended: "C Video Tutorial"

When describing a structure variable, the memory allocated to it by the system is the sum of the memory required by each member.

The memory length occupied by structure variables is the sum of the memory lengths occupied by each member. Each member occupies its own memory unit, and the memory length occupied by the union variable is equal to the length of the longest member.

Related introduction:

C provides many basic data types (such as int, float, double, char, etc.) for users to use. However, since the problems that programs need to deal with are often complex and diverse, existing data types cannot meet the usage requirements. Therefore, C allows users to declare some types according to their needs. The types that users can declare themselves include structure types (structure), union types (union), enumeration types (enumeration), class types (class), etc. These are collectively called User-defined type (UDT).

The above is the detailed content of What memory is allocated to a structure variable by the system when it is defined?. 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