天天看点

C语言(三):字符与运算符

C语言(三):字符与运算符

分享兴趣,传播快乐,

增长见闻,留下美好!

亲爱的您,这里是LearningYard新学苑。

今天小编为大家带来的是C语言(三):字符与运算符。

Share interests, spread happiness,

increase knowledge, and leave good!

Dear you, this is the Learning Yard.

Today, Xiaobian brings you C language (III): characters and operators.

01

字符和字符串

(1)%c对应字符,%s对应字符串

(1) % c corresponds to character,% s corresponds to string

(2)ASCII表的运用

(2) Application of ASCII table

C语言(三):字符与运算符

(3)字符串

①声明字符串:char 变量名[数量]

例如:char name[3](声明3个字符)

②给字符串赋值:(从0开始)

name[0]='p';

name[1]='i';

name[2]='g';

③定义字符串

char name[3]={'p','i','g'};

多种表示方法:

(3) String

① declaration string: char variable name [quantity] Example: char name [3] (declaration of 3 characters)

② assignment to string: (starting from 0)

name [0]='p';

name[1]='i';

name[2]='g';

③ The definition string char name [3]={'p', 'i', 'g'}; Multiple representations:

C语言(三):字符与运算符

02

算术运算符

(1)%(求余)运用于整数类型

(1) % (remainder) applied to integer type

(2)类型转换

一般将整型转化为浮点型,需要用%f输出

例如:

(2) Type conversion generally converts an integer type to a floating-point type, and requires% f output, for example:

C语言(三):字符与运算符

整型输出结果错误,因为计算过程中将1转化为了1.0,需要用浮点型输出

The integer output result is incorrect, because 1 is converted to 1.0 in the calculation process, and the floating-point output is required

(3)强制转换

(3) Cast

C语言(三):字符与运算符

03

关系运算符和逻辑运算符

(1)关系运算符

(1) Relational operators

C语言(三):字符与运算符

例:(1为真,0为假)

Example: (1 is true, 0 is false)

C语言(三):字符与运算符

(2)逻辑运算符

(2) Logical operator

运算符

operator

含义

meaning

优先级

priority

说明

explain

wrong

high

如a为真,则!a为假

If a is true, then! A is false

&&

And

in

一假为假

One false is false

||

or

low

一真则真

One true is true

(3)短路求值

(3) Short-circuit evaluation

C语言对逻辑与与逻辑或采用短路求值

C language uses short circuit evaluation for logical AND logic or

对于逻辑与(&&)来说,从左往右判断,同时为真才执行。

对于逻辑或(||)来说,从左往右判断,如果前面有一个表达式为真,就不管后面的表达式。

For logical and (&&), judge from left to right, and execute for real talent at the same time. For logical OR (| |), judge from left to right. If one of the preceding expressions is true, the following expressions are ignored.

END

今天的分享就到这里了。

如果您对今天的文章有独特的想法,

欢迎给我们留言,

让我们相约明天,

祝您今天过得开心快乐!

That's all for today's sharing.

If you have unique ideas about today's article,

please leave us a message.

Let's meet tomorrow and wish you a happy day!

翻译:百度翻译

参考:《零基础入门学习C语言:带你学C带你飞》、哔哩哔哩小甲鱼视频、网络图片

声明:本文由LearningYard新学苑原创,若有侵权请联系删除!

关注我们

文案&排版:易春秀

审核:闫庆红