当前位置:网站首页>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):采用中文输入导致运行失败
边栏推荐
猜你喜欢

chapter7

Creating seven NiuYun Flask project complete and let cloud

Deep learning framework pytorch rapid development and actual combat chapter3

Briefly write about the use and experience of PPOCRLabel

Camera Hal(Hal3)层修改Preview流

【c】大学生在校学习c语言常见代码

使用云GPU+pycharm训练模型实现后台跑程序、自动保存训练结果、服务器自动关机

chapter7
![[ROS] (05) ROS Communication - Node, Nodes & Master](/img/f5/c541259b69a0db3dc15a61e87f0415.png)
[ROS] (05) ROS Communication - Node, Nodes & Master

瑞吉外卖笔记——第08讲读写分离
随机推荐
重新学习编程day1 【初始c语言】【c语言编写出计算两个数之和的代码】
The specific operation process of cloud GPU (Hengyuan cloud) training
Unit 5 Hold Status
Paddle window10 environment using conda installation
Visual Studio配置OpenCV之后,提示:#include<opencv2/opencv.hpp>无法打开源文件
【Camera2】由Camera2 特性想到的有关MED(多场景设备互动)的场景Idea
Unit 8 Middleware
8576 Basic operations of sequential linear tables
Unit 3 view layer
【ROS】编译软件包packages遇到进度缓慢或卡死,使用swap
[ROS]ROS常用工具介绍(待续)
Haystack的介绍和使用
Introduction and use of Haystack
二级指针,数组指针,指针数组和函数指针
[ROS] The software package of the industrial computer does not compile
8576 顺序线性表的基本操作
函数递归和动态内存初识
[ROS](01)创建ROS工作空间
The 2nd China Rust Developers Conference (RustChinaConf 2021~2022) Online Conference Officially Opens Registration
Flask请求应用上下文源码分析