The sizeof() function is the same as the sizeof() function.
Its core function is to determine the length of the data type, first through a practical example.
As you can see from the above example, both character and unsigned characters are 1 in length, and both integer and unsigned integer are 2 in length. The length of the character array cs is 8, where the character length is 7 plus the terminator, making up 8 bytes. The string pointer PCS is 3 in length. The following three Pointers x9, X12 and X16 are 3 in length. Although X16 is an integer and x9 and x12 are characters, they still occupy 3 bytes of memory inside the MCU. X11 takes up 9 bytes. X11 is an array of Pointers that contains a total of 3 Pointers. Note A pointer also occupies three bytes.
The sizeof a pointer variable has nothing to do with the object to which the pointer refers. All pointer variables take up the same amount of memory.
The sizeof an array is equal to the number of bytes of memory the array occupies, regardless of the sizeof the contents stored in the array. So when we count the number of arrays in array IS, we can write
len = sizeof(is) /sizeof(int);
Copy the code
Or you could write it as
len = sizeof(is) /sizeof(is[0]);
Copy the code
Divide the size of an element by the size of an element in bytes.
To summarize the usage of sizeof(), use a sentence from Baidu Baike.