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

瑞吉外卖笔记——第08讲读写分离

What's wrong with running yolov5 (1) p, r, map are all 0

瑞吉外卖笔记——第05讲Redis入门

paddleocr window10 first experience

C语言一级指针(补)

redis分布式锁和看门狗的实现

Creating seven NiuYun Flask project complete and let cloud

8581 线性链表逆置

Raj delivery notes - separation 第08 speak, speaking, reading and writing

Implementation of redis distributed lock and watchdog
随机推荐
[ROS](04)package.xml详解
8580 合并链表
STM32 (F407) - stack
PHP open source customer service system _ online customer service source code PHP
ftp常用命令详解_iftop命令详解
[ROS] (06) ROS Communication - Topic Communication
static关键字3种作用,简单粗暴对比,好理解
run yolov5
redis分布式锁和看门狗的实现
The IDEA of packaged jar package
8576 顺序线性表的基本操作
Unit 10 Continuous Tuning
初识c语言指针
Flask-RESTful request response and SQLAlchemy foundation
猜数字游戏,猜错10次关机(srand、rand、time)随机数生成三板斧(详细讲解!不懂问我!)
MarkDown syntax summary
yolov5 improvement (1) Add attention focus mechanism
Verilog Learning Series
St. Regis Takeaway Notes - Lecture 10 Swagger
drf路由组件Routers