当前位置:网站首页>C语言日记 4 变量
C语言日记 4 变量
2022-08-02 14:03:00 【宇 -Yu】
赋值:
例:
#include<iostream>
using namespace std;
int main()
{
int a,b,c = 5;
}
即a,b没有赋初值,c赋初值为5。
在给同一类型不同变量赋值时,注意中间必须用逗号而不要用分号。例:
#include <iostream>
using namespace std;
void main()
{
int x = 5; r = 8; a= 9; b = 10;
cout << (x + r) * 8 - (a + b) / 7;
}

正确方式:
#include <iostream>
using namespace std;
void main()
{
int x = 5, r = 8, a= 9, b = 10;
cout << (x + r) * 8 - (a + b) / 7;
}
在定义中不允许连续赋值,例:(不在定义中连续赋值就不知道是什么情况了,反正我们现在也不知道什么时候不在定义中赋值)
#include<iostream>
using namespace std;
int main()
{
int a=b=c=5;
}
结果:

书本P20例2-1:
#include<iostream>
using namespace std;
int main()
{
int a = 3, b, c = 5;
b = a + c;
cout << "a=" << a << " , b = " << b << " , c = " << c << endl;
}
结果:
a=3 , b = 8 , c = 5
赋值的另一种形式,例:
#include<iostream>
using namespace std;
int main()
{
int a(5);
cout << a;
}
等价于int a=5;
本例中遇到过的问题:
#include<iostream>
using namespace std;
int main()
{
int a(5);
cout << a;
}

错误原因: int a(5):采用中文输入导致运行失败
边栏推荐
- PHP open source customer service system _ online customer service source code PHP
- verilog学习|《Verilog数字系统设计教程》夏宇闻 第三版思考题答案(第七章)
- ToF相机从Camera2 API中获取DEPTH16格式深度图
- The language of initial
- 【Camera2】由Camera2 特性想到的有关MED(多场景设备互动)的场景Idea
- c语言三子棋详解!!! (电脑智能下棋)(附上完整代码)
- (ROS) (03) CMakeLists. TXT, rounding
- window10下半自动标注
- run yolov5
- [ROS] Introduction to common tools in ROS (to be continued)
猜你喜欢

MobileNet ShuffleNet & yolov5 replace backbone

(ROS) (03) CMakeLists. TXT, rounding

宏定义问题记录day2

The specific operation process of cloud GPU (Hengyuan cloud) training

Deep learning framework pytorch rapid development and actual combat chapter4

Error Correction Design Principle of Hamming Check Code

Building and getting started with the Flask framework

跑yolov5又出啥问题了(1)p,r,map全部为0

MarkDown语法汇总

重新学习编程day1 【初始c语言】【c语言编写出计算两个数之和的代码】
随机推荐
Unit 4 Routing Layer
c语言三子棋详解!!! (电脑智能下棋)(附上完整代码)
海明校验码纠错设计原理
关于密码加密的一点思路
第四单元 路由层
【ROS】工控机的软件包不编译
[ROS]roscd和cd的区别
MarkDown语法汇总
verilog学习|《Verilog数字系统设计教程》夏宇闻 第三版思考题答案(第十三章)
网络剪枝(1)
Flask框架的搭建及入门
PHP open source customer service system _ online customer service source code PHP
使用云GPU+pycharm训练模型实现后台跑程序、自动保存训练结果、服务器自动关机
Briefly write about the use and experience of PPOCRLabel
浅浅写一下PPOCRLabel的使用及体验
redis delay queue
A little thought about password encryption
chapter7
verilog学习|《Verilog数字系统设计教程》夏宇闻 第三版思考题答案(第十二章)
xshell连接虚拟机步骤_建立主机与vm虚拟机的网络连接