Chapter 3rd Data
In C, there are only 4 basic data Types-integer, float, pointer, and aggregation type (such as arrays, structs, and so on).
Integral types: characters, short integers, and long integers, both of which are classified as signed (signed) and unsigned (unsigned).
short int at least 16 bits, long int at least 32 bits.
ANSI C allows a named constant (named constant, a variable declared as const), which cannot be changed after it is initialized.
How to use a value as a character constant:
value = value-48;
Value = value-\60;
Value = value-' 0 ';
Enum type
An enumeration (enumerated) type means that its value is a symbolic constant rather than a literal type:
Enum Jar_type{cup,pinr,quart,half_gallon,gallon};
Enum Jar_type Milk_jug, Gas_can, Medicine_bottle;
==
enum {CUP, PINT, quart, Half_gallon, gallon} milk_jug,gas_can,medicine_bottle;
This type of variable is actually stored as an integer, and the actual value of these symbol names is an integer value. Here the Cup is 0,pint is 1, and so on.
You can specify a specific integer value for these symbol names.
Enum Jar_type{cup = 8, PINT = +, quart = +, Half_gallon =, gallon = 128};
It is also legal to assign only part of the symbol name in this way. If a symbol name does not explicitly specify a value, its value is 1 larger than the value of the previous symbol name.
Floating-point types
The floating-point family includes the float, double, and long double types.
A floating-point value is a double type by default, unless it is followed by an L or l indicating that it is a long double, or with an F or f indicating that it is a value of type float.
Pointer
The value of the variable is stored in the computer's memory, and each variable occupies a specific location. Each memory location is uniquely determined and applied by the address. The pointer is just another name for the address. A pointer variable is a variable whose value is 01 (some) memory address.
First, pointer constant (pointer constant)
Pointer constants are inherently different from non-pointer constants because the compiler is responsible for assigning variables to locations in the computer's memory, which the programmer does not know beforehand that a particular variable will be stored in the memory location. Therefore, you get the address of a variable by using an operator instead of simply writing its address as a constant form of literal value. For example, if we want to know the address of the variable xyz, we cannot write a literal value like OXFF2044EC, because we do not know if this is the actual memory location of the official store. In fact, when a function is called each time, his automatic variables (local variables) may be assigned different memory locations each time. Therefore, it is almost useless to recognize a pointer constant as a numeric literal.
Second, string constant (string literal)
There is no string type for C language.
ANSI C declares that if a string constant is modified, its effect is undefined.
is because using a string constant in a program produces a pointer to a constant that is a character. When a string constant occurs in an expression, the value used by the expression is the address that these characters store, not the characters themselves.
The following two effects are equivalent:
unsigned short int A;
unsigned short A;
int is signed by default.
Another notable point of the C array is that the compiler does not check whether the program's reference to the array's subscript is within the legal bounds of the arrays.
If the subscript value is calculated from a value that is known to be correct, then it is not necessary to check its value. If a value used as a subscript is generated from user input data based on a method, it must be instrumented before using it to ensure that they are in a valid range.
declaring pointers
int *a;
==
Int* A;
But int* A,b,c;
!=
int *a,*b,*c;
typedef
The C language supports a mechanism called TypeDef, which allows you to define new names for various data types.
Char *ptr_to_char;
Ptr_to_char is a character pointer;
typedef char *PTR_TO_CHAR;
Ptr_to_char A;
Declaring A is a pointer to a character.
Tips:
You should use typedef instead of # define to create new type names, which do not handle pointer types correctly.
#define D_PTR_CHAR char*
D_ptr_to_char A, B;
b cannot declare a pointer.
Constant
const int A;
Pointers on C (Day 1,chapter3)