Before using bool, declare # include <stdbool. h> (this header file defines macros such as bool, true, and false) int A [5]; sizeof (A [5]), sizeof is a keyword, and the evaluation value is during compilation, sizeof (A [5]) does not report an error. This value does not exist, but it does not actually access the value of a [5, instead, the value is determined only based on the type of the array element. Sizeof (variable \ constant) sizeof variable \ constant sizeof (data type) sizeof data type -- Error * sizeof
Sizeof is one of the C operators used to obtain the memory space allocated to the operands, expressed in bytes.
The operands can be variables or data types, such as int and float. Therefore, you can use them to obtain the range of basic types defined by the local C library.
* Use of sizeof
1. For general variables, there are two forms: sizeof A or sizeof ();
2. For data types, brackets must be used, such as sizeof (INT ).
* Description of size_t
The return value of sizeof must be an unsigned integer. In Standard C, the return value type is defined as size_t (namely, unsigned int, defined in stddef. h In the header file). strlen also returns an unsigned integer. If the size_t type is output using printf, the format character % ZD is defined in c99; if the compiler does not support % u or % lu/% ZD.
* Comparison with strlen
Sizeof: obtains the number of bytes in the memory space occupied by the operands. The return type is size_t;
Strlen: obtains the actual number of bytes used by the character array. It does not contain the array Terminator '\ 0' and returns the type size_t;
As shown in:
# Include <stdio. h>
# Include <string. h>
Int main (void)
{
Int A = 1;
Char B [4] = "AAA ";
Printf ("% ZD % lu \ n", sizeof A, sizeof (INT), sizeof );
Printf ("% ZD \ n", sizeof B, strlen (B ));
Return 0;
}
Result:
4 4 4
4 3
Bool, sizeof