struct, common body, enumeration type of sizeof1) enumeration class enum-type space calculationAn enum simply defines a set of constants with no "elements", and the enumeration type is stored as an int, so the sizeof value of the enumeration type is
I. sizeofSizeof (...) is an operator. In the header file, typedef is an unsigned Int. Its value is calculated after compilation. The parameter can be an array, pointer, type, object, function, etc.Its function is to obtain the maximum object size
In C + + we often use sizeof () to calculate the size of an arrayFor example:1#include 2 using namespacestd;3 4 voidLength (int*p)5 {6coutsizeof(p) " "sizeof(int) Endl;7 }8 9 intMain ()Ten { One intN; A intPirce[] = {0,1,5,8,9,Ten, -, -, -,
Recently in the Forum has always been asked about sizeof, and I have not been a very good solution to this problem, simply today to it to a more detailed summary, and combined with strlen for comparison, if you have a bit of help, this is my
I. Introduction in the previous article, we created a window from scratch. One important step is to register the window class, such as the following code://Register window class bool Register (LPSTR lpclassname, WNDPROC WNDPROC) {wndclassex WCE = {0}
learned the sizeof reserved word to get the number of bytes for different variables. However, the number of bytes is machine dependent.#include /** * Output the size of common variables * @brief main * @return */intMainvoid) {printf ("%s\n","Now We'
(1): The result of the sizeof operator is size_t. The typedef in the header file is of the unsigned int type.
(2): sizeof is an operator.
(3) sizeof can be used as a parameter.
(4) the sizeof parameter of the array is not degraded. If it is
The difference and connection between sizeof and strlenFirst,sizeofsizeof (...)is an operator, in the header filetypedefto beunsigned int, the values are calculated at compile time, and the parameters can be arrays, pointers, types, objects,
Function prototype: size_t strlen (const char * Str)
Return Value: returns the number of characters in the string, excluding the terminator '/0 '. If no return value is returned, an error occurs;
Parameter description: Str: string with '/0' as the
1.sizeof is the operator, which is essentially the same as the nature of the subtraction, executed at compile time, not at runtime.So what if this is validated in programming? PS: This is the first two days of friends Taobao interview a problem ,
first part macro definition
Syntax format for macro definition: #define Example 1: Use #define to implement macros and find the maximum value.
#define MAX ((x) > (y)) (X,y) (x):(y))
Note in the macro you need to carefully enclose the
In general, do not apply the sizeof operator to the pointer when getting the length of an array .
Now take a look at the following code:
void clear (int array[]) {for
(size_t i = 0; i
Clear () uses sizeof (array)/sizeof (Array[0]) to
Difference between Strlen () and Sizeof (); Difference between strlensizeof
The strlen () function is used to calculate the actual length of a string. It is obtained from the beginning to the First '\ 0'. If you only define that it is not assigned
Array name take the address is very fun, here to record, if you have different views, welcome message discussion:in most cases, the array name is converted by default to a pointer to the first element of the array . This is a point that we all know.
At first, my problem was:
Char intarray [] = "wo Shi shui ";Int Len = sizeof intarray;Cout The output is 12.Char * intarray = "wo Shi shui ";Int Len = sizeof intarray;Cout Output is 4
Why is one output 12 and one output 4. because I think that the
The operator in C is sizeof (type_name) and can be used with any variable name, type name, or constant value, and it does not need parentheses when used for variable names (not array names) or constants. Note that sizeof is an operator, and it works
sizeof is a keyword in c/s + + that is an operator that takes the length of an object (data type or data object) (that is, the size of the memory, in bytes). Types include basic data types (excluding void), user-defined types (struct, class),
First,sizeofsizeof (...)is an operator, in the header filetypedefto beunsigned int, the values are calculated at compile time, and the parameters can be arrays, pointers, types, objects, functions, and so on. its function is to ensure that the size
Mainly for the identification of int long char double byte length.1 #include 23 int Main ()6 95 int a[100];6 int (*p) [100];7 p=&a;89 Long b[100];Ten long (*P2) [100];p2=&b;12Double c[100];Double (*P3) [100];p3=&c;16+ Char d[100]=
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.