How to use C _ Candle + basic sizeof
The main content of this article is to explain "how to use C _ + basic sizeof". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to use Candlestick + basic sizeof"!
Sizeof () is an operator that determines the type of data or the length of an expression in C _ blank +.
1. Sizeof defines sizeof as an operator (operator) in Cplink +, which returns the number of bytes of memory occupied by an object or type.
The sizeof keyword gives the amount of storage, in bytes, associated with a variable ora type (including aggregate types). This keyword returns a value of type size_t.
-- from MSDN
The return value type is size_t and is defined as: typedef unsigned int size_t in the header file stddef.h
From the definition of sizeof, you can see that sizeof is not a function, because a function call must have a pair of parentheses.
# include int main (void) {int num = 97; printf ("value of sizeof (num = 0):% d\ n", sizeof (num = 0)); printf ("value of num:% d\ n", num); return 0;}
The running result is 4pjm 97; it is not 4pas 0
Note: sizeof is not a unary operator in the standard sense, chain expressions are not supported, and statements within the scope of sizeof will not be compiled into machine code, such as + + in sizeof (num++). Sizeof is not a function either. Sizeof is more like a special macro that is evaluated at compile time.
2. Sizeof usage sizeof has two grammatical forms, as follows:
Sizeof (type_name); / / sizeof (type); sizeof (object); / / or sizeof object all belong to sizeof objects
So:
Int i; sizeof (I); / / reasonable sizeof I; / / reasonable sizeof (int); / / reasonable sizeof int; / / unreasonable
When using sizeof on a type, sizeof type_name is illegal and must be written as sizeof (type_name)
Whether it is a value for an object or a type, the form sizeof () is correct
1) sizeof of basic data types
The basic data types here refer to simple built-in data types such as short, int, long, float, and double.
Because their memory size is related to the system, the values may be different in different systems.
# include using namespace std; int main () {cout