天天看點

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新學苑原創,若有侵權請聯系删除!

關注我們

文案&排版:易春秀

稽核:闫慶紅