当前位置:网站首页>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;
}边栏推荐
- How to pass values to onclick events in thymeleaf
- NOI OJ 1.4 04:奇偶ASCII值判断 C语言
- 漫画 | Code Review快把我逼疯了!
- 2021-05-11抽象类
- Set up a QQ robot for ordering songs, and watch beautiful women
- 2021-05-12 interface definition and Implementation
- Comic | code review is driving me crazy!
- J. Med. Chem. | Release: a new drug design model for deep learning based on target structure
- 2021-04-15
- 2021-05-07封装 继承 super this
猜你喜欢

Bioinformatics | effective drug target correlation prediction based on interacting neural network

Golang quick start (3)

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

Successful experience of postgraduate entrance examination in materials and Chemical Engineering (metal) of Beijing University of Aeronautics and Astronautics in 2023

Build the information and innovation industry ecology, and make mobile cloud based on the whole stack of independent innovation

文献综述怎么写 ,一直没头绪写不出来怎么办?

JVM简单入门-02

Golang quick start (1)

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

NFTs、Web3和元宇宙对数字营销意味着什么?
随机推荐
File IO (1)
Different methods of PivotTable in SQL tutorial
Data structures and differences between MySQL InnoDB engine and MyISAM
MySQL基础-笔记
Unity技术手册 - 生命周期内速度限制(Limit Velocity Over Lifetime)子模块和速度继承(Inherit Velocity)子模块
几款实用软件分享
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
SQL writing problem to calculate the ring ratio of the current month and the previous month
同花顺推荐么?手机开户安全么?
Tencent tangdaosheng: practice "science and technology for the good" and promote sustainable social value innovation
2021-05-11static关键字
Is there anyone who plans to open source an industrial "seckill" system architecture?
regular expression
漫画 | Code Review快把我逼疯了!
Cool photo album code, happy birthday to the object!
laravel8 beanstalk 使用说明
NFTs、Web3和元宇宙对数字营销意味着什么?
马斯克 18 岁儿子请愿改名,欲断绝父子关系
Build the information and innovation industry ecology, and make mobile cloud based on the whole stack of independent innovation
High performance computing center nvme / nvme of nvme of overview