当前位置:网站首页>NOI OJ 1.2 10:Hello, World!的大小 C语言
NOI OJ 1.2 10:Hello, World!的大小 C语言
2022-06-23 10:12:00 【chd44】
描述
还记得在上一章里,我们曾经输出过的“Hello, World!”吗?
它虽然不是本章所涉及的基本数据类型的数据,但我们同样可以用sizeof函数获得它所占用的空间大小。
请编程求出它的大小,看看跟你设想的是否一样?
输入
无。
输出
一个整数,即“Hello, World!”的大小。
先来一个明显的错误示范(大佬别喷)
#include<stdio.h>;
int main(){
char a=" Hello, World!";
printf("%d",sizeof(a));
return 0;
}这个是错误代码!!!!!!!!!!!
char是用来存放字符数据的,例:'x'和 '*'
在此处" Hello, World!"明显超出了这个范围,因此我们没有必要先用char来声明,我们可以直接输出sizeof(" Hello, World!"),这样得出的值就是整数,可以直接输出。
正确代码:
#include<stdio.h>
int main(){
printf("%d",sizeof("Hello, World!"));
return 0;
}边栏推荐
猜你喜欢

2021-04-15

MySQL基础-笔记

Nuxt.js spa与ssr的区别

云原生数据库-Amazon RDS

Copilot免费时代结束!正式版67元/月,学生党和热门开源项目维护者可白嫖

IPv6 的速度比 IPv4 更快?

Dr. Sun Jian was commemorated at the CVPR conference. The best student thesis was awarded to Tongji Ali. Lifeifei won the huangxutao Memorial Award

Unity技术手册 - 生命周期内速度限制(Limit Velocity Over Lifetime)子模块和速度继承(Inherit Velocity)子模块

STM32F1与STM32CubeIDE编程实例-红外寻迹传感器驱动

The era of copilot free is over! The official version is 67 yuan / month, and the student party and the defenders of popular open source projects can prostitute for nothing
随机推荐
Successful experience in postgraduate entrance examination for MTI master of English translation major of Beijing University of science and technology in 2023
2021-04-16 method overload parameter transfer
High performance computing center Infiniband overview
Cloud native database Amazon RDS
太无奈!微软停售 AI 情绪识别等技术,直言:“法律跟不上 AI 的发展”
2021-05-12接口的定义与实现
用贪吃蛇小游戏表白(附源码)
2021-04-27类和对象
Golang quick start (1)
【软件与系统安全】堆溢出
2021-05-11instanceof和类型转换
Golang 快速上手 (3)
2021-04-12 the first implementation of linked list!!!
XML related interview questions
2021-04-16 recursion
SQL writing problem to calculate the ring ratio of the current month and the previous month
On shore experience of Chang'an University majoring in transportation in 2023
File IO (1)
Simple understanding of quick sort
Fill the pit for repvgg? In fact, it is the repoptimizer open source of repvgg2