Home >Backend Development >C#.Net Tutorial >How to use size in c language
size macro is used in C language to get the byte size of a data type. Syntax: size(data_type). It accepts a data type as a parameter and returns the number of bytes occupied by the data type on the compiler.
size usage in C language
size
is a preset of C language Processor macro for getting the byte size of a data type.
Usagesize
The macro accepts a data type as a parameter and returns the number of bytes occupied by the data type on the compiler. The syntax is as follows:
<code class="c">size(data_type)</code>
Among them:
data_type
is the data type of the byte size to be queried. Return valuesize
The macro returns an integer indicating the number of bytes occupied by the specified data type on the compiler.
Example
<code class="c">#include <stdio.h> int main() { printf("Size of int: %zu\n", size(int)); printf("Size of float: %zu\n", size(float)); printf("Size of double: %zu\n", size(double)); printf("Size of char: %zu\n", size(char)); }</code>
Output:
<code>Size of int: 4 Size of float: 4 Size of double: 8 Size of char: 1</code>
In this example, the size
macro is used to determine the int The size in bytes of the
, float
, double
, and char
data types on the compiler.
The above is the detailed content of How to use size in c language. For more information, please follow other related articles on the PHP Chinese website!