Home > Backend Development > C#.Net Tutorial > How to use size in c language

How to use size in c language

下次还敢
Release: 2024-05-08 13:54:15
Original
421 people have browsed it

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.

How to use size in c language

size usage in C language

size is a preset of C language Processor macro for getting the byte size of a data type.

Usage
size 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>
Copy after login

Among them:

  • data_type is the data type of the byte size to be queried.

Return value
size 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>
Copy after login

Output:

<code>Size of int: 4
Size of float: 4
Size of double: 8
Size of char: 1</code>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template