Home >Backend Development >C#.Net Tutorial >What is the role of sizeof in c language
sizeof is used in C language to get the number of bytes of a data type or variable. Its function is as follows: Get the number of bytes of a basic data type. Get the number of bytes of an array element. Get the number of bytes in a structure or union. Get the number of bytes of the data type pointed to by the pointer variable. Allocate memory.
The role of sizeof in C language
sizeof is an operator in C language, used to obtain The number of bytes occupied by the data type or variable. It is a compile-time operator that calculates and returns the size of a specified data type or variable during the compile phase.
Function:
Syntax:
<code class="c">sizeof(数据类型或变量)</code>
Example:
<code class="c">#include <stdio.h> int main() { int i; int *p; printf("sizeof(int): %ld\n", sizeof(int)); printf("sizeof(i): %ld\n", sizeof(i)); printf("sizeof(*p): %ld\n", sizeof(*p)); return 0; }</code>
Output:
<code>sizeof(int): 4 sizeof(i): 4 sizeof(*p): 4</code>
In this In the example:
The above is the detailed content of What is the role of sizeof in c language. For more information, please follow other related articles on the PHP Chinese website!