当前位置:网站首页>NOI OJ 1.2 10:Hello, World! Size of C language

NOI OJ 1.2 10:Hello, World! Size of C language

2022-06-23 10:29:00 chd44

describe

Remember in the last chapter , We have output “Hello, World!” Do you ?

Although it is not the basic data type involved in this chapter , But we can also use sizeof Function to get the size of the space it occupies .

Please program to find its size , See if it's the same as you think ?

Input

nothing .

Output

An integer , namely “Hello, World!” Size .

Let's start with an obvious error demonstration ( Don't spray )

#include<stdio.h>;
int main(){
char a=" Hello, World!";
printf("%d",sizeof(a));
return 0;
}

This is the error code !!!!!!!!!!!

char Is used to store character data , example :'x' and   '*'

Here, " Hello, World!" Obviously beyond this range , So we don't have to use char To declare , We can output directly sizeof(" Hello, World!"), The resulting value is an integer , You can export it directly .

Correct code :

#include<stdio.h>
int main(){
printf("%d",sizeof("Hello, World!"));
return 0;
}

原网站

版权声明
本文为[chd44]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206231012356759.html