C language study notes - Custom Type

  1. Types and variables what's the difference?

Variable assignment can only access and operation, and can not be assigned to a type of access and operation. At compile time, type of space is not allocated, only allocate space for variables.

  1. If the pointer ppoints to a structure variable stu, is equivalent to the following three uses:

    • . stu member name (such as stu.num);
    • . (* p) member name (such as (*p).num);
    • p -> member name (such as p -> num);
  2. What is the common body type?

Sometimes you want to store different types of variables with the same period of the memory unit. For example, to a shortvariable, a charvariable, and a floatvariable in memory cells of the same start address. Three or more different number of bytes for a variable in memory, but are stored starting from the same address, which is used to cover technology, after a front cover data data. Several different variables such that the same segment of memory sharing structure, of the type known as "union" structure.
The general form of the type defined in common:

union 共用体名{
    成员表列
} 变量表列;

for example:

union Data {
    int a;
    char b;
    float c;
} data_1, data_2;

I think the usage scenario is: a member of a structure variable attributes to be determined, and use unionto avoid re-add a member property or re-definition of a structure type.

  1. Enumerated types, usually in the form of an enumeration type declaration is as follows:
enum 枚举名 {
    枚举元素列表
} 变量名列表;

for example:

enum color {
    red, blue, dark
} my_color, your_color;
  1. typedef with #define

#defineIs treated in the pre-compile time, it can only make a simple string replacement, and typedefis compiled in the processing stages of

More differences: https://blog.csdn.net/xing1314/article/details/2336269

Guess you like

Origin www.cnblogs.com/zgglj-com/p/12637520.html