c语言语言教程0基础_C语言基础
c語言語言教程0基礎(chǔ)
Hey, Folks here I am back with my second article on C language. Hope you are through with my previous article C language - History, Popularity reasons, Characteristics, Basic structure etc. In this one, I will cover some fundamental concepts of C Language namely Variables, Tokens, Operators in C language.
嘿,伙計(jì)們,我回來了第二篇有關(guān)C語言的文章。 希望您能讀完我以前的C語言文章-歷史,流行原因,特征,基本結(jié)構(gòu)等 。 在這一篇中,我將介紹C語言的一些基本概念,即C語言中的變量,標(biāo)記,運(yùn)算符 。
Let’s get started...
讓我們開始吧...
1)變量 (1) Variables)
They are temporary memory locations allocated during execution of the program. As the name suggests it is an entity whose value may change during program execution.
它們是在程序執(zhí)行期間分配的臨時(shí)內(nèi)存位置。 顧名思義,它是一個(gè)在程序執(zhí)行期間其值可能會更改的實(shí)體。
Rules for variable name
變量名規(guī)則
It does not have a space between characters.
字符之間沒有空格。
Collection of alphabets, digits, and underscore (_).
字母,數(shù)字和下劃線(_)的集合。
The first character should be either alphabet or underscore (_).
第一個(gè)字符應(yīng)為字母或下劃線(_)。
No other special symbol except underscore (_).
除下劃線(_)外,沒有其他特殊符號。
Keywords cannot be used as variable name.
關(guān)鍵字不能用作變量名。
Declaration of variable
變量聲明
Syntax:
句法:
datatype variable_name;Example:
例:
int a;It tells the user what is the data type of a declared variable or what type of values it can hold.
它告訴用戶聲明的變量的數(shù)據(jù)類型是什么或它可以保存的值的類型。
Initialization of a variable
初始化變量
The process of assigning any value to any variable.
將任何值分配給任何變量的過程。
Example:
例:
int a = 5;2)代幣 (2) Token)
The basic and smallest unit of C program is token.
C程序的基本最小單位是令牌。
Token includes :
令牌包括:
Keywords
關(guān)鍵詞
Identifier
識別碼
Constants
常數(shù)
String Constant
字符串常量
Operators
經(jīng)營者
Special Symbols e.g: _ , @ , *
特殊符號,例如:_,@,*
1) Keywords or Reserve words
1)關(guān)鍵字或保留字
These are those words whose meaning is already explained to the compiler.
這些是已經(jīng)向編譯器解釋其含義的單詞。
They can’t be used as a variable name because if we do so that means we are defining the new meaning to the compiler which the compiler does not allow.
它們不能用作變量名,因?yàn)槿绻@樣做,則意味著我們正在為編譯器定義編譯器不允許的新含義。
2) Identifier
2)識別碼
They are the name given to programming elements such as array, function, variable. Same rules as of variable name.
它們是諸如數(shù)組,函數(shù),變量之類的編程元素的名稱。 與變量名相同的規(guī)則。
3) Constant
3)常數(shù)
Entities whose value does not during the execution of a program.
其值在程序執(zhí)行期間不存在的實(shí)體。
4) String constant
4)字符串常量
Collection of character enclosed by a double inverted comma. e.g.: "abc"
用雙反逗號括起來的字符的集合。 例如: “ abc”
5) Operators
5)運(yùn)營商
They are used to perform arithmetic and logical operations by ALU.
它們由ALU用于執(zhí)行算術(shù)和邏輯運(yùn)算。
Example:
例:
a+bHere, a and b are operands and + is an operator.
在這里, a和b是操作數(shù),而+是運(yùn)算符。
C language has very rich operators. Many different types of operators are available in C language for different mathematical computations.
C語言具有非常豐富的運(yùn)算符。 C語言提供了許多不同類型的運(yùn)算符,用于不同的數(shù)學(xué)計(jì)算。
They are mainly of three types:
它們主要分為三種類型:
.minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}} .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}}Operators itself is a separate topic which needs to be covered in detail.
運(yùn)營商本身是一個(gè)單獨(dú)的主題,需要詳細(xì)介紹。
So, here we get started.
所以,我們開始。
Unary operators
一元運(yùn)算符
They require only one operand for execution, it includes :
它們只需要一個(gè)操作數(shù)即可執(zhí)行,其中包括:
Unary minus
一元減
Bitwise compliment
按位贊美
Logical Not
邏輯不
Increment / Decrement
增量/減量
sizeof() operator
sizeof()運(yùn)算符
sizeof() Operator
sizeof()運(yùn)算符
It is used to return the size of an operand. It can be applied on variable, constant, datatype.
它用于返回操作數(shù)的大小。 它可以應(yīng)用于變量,常量,數(shù)據(jù)類型。
Syntax:
句法:
sizeof(operand);Example:
例:
int a=2, b;b = sizeof(a);//orb = sizeof(int);//orb = sizeof(5);printf("%d\n",b);//All of the 3 three statements will give same output.Ternary operators
三元運(yùn)算符
They are also called conditional operator. For these operators, we require 3 operands for execution. There is only and one ternary operator in C language.
它們也稱為條件運(yùn)算符。 對于這些運(yùn)算符,我們需要3個(gè)操作數(shù)來執(zhí)行。 用C語言只有一個(gè)三元運(yùn)算符。
Syntax:
句法:
expression_1 ? expression_2 : expression_3 ;If expression_1 is true expression_2 gets executed, if false then expression_3.
如果expression_1為true,則執(zhí)行expression_2 ,如果為false,則執(zhí)行expression_3 。
Example:
例:
int a=4 , b=7 , c;c = ( a<7 ? a:b );printf("%d\n", c );Output
輸出量
4Since, a = 4, exp_1 is true and therefore exp_2 gets executed. So, c = a gets executed.
由于a = 4 , exp_1為true,因此exp_2被執(zhí)行。 因此, c = a被執(zhí)行。
Binary operators
二元運(yùn)算符
i) Arithmetic operators
i)算術(shù)運(yùn)算符
| Operator name | Operator |
| Addition | + |
| Subtraction | - |
| Multiplication | * |
| Division | / |
| Modulus | % |
| 操作員姓名 | 操作員 |
| 加成 | + |
| 減法 | -- |
| 乘法 | * |
| 師 | / |
| 模量 | % |
Modulus operator gives remainder and division operator gives quotient. All arithmetic operators can be used for integer and float values except modulus which is used for integers only.
模運(yùn)算符給出余數(shù),除法運(yùn)算符給出商。 除模數(shù)僅用于整數(shù)外,所有算術(shù)運(yùn)算符均可用于整數(shù)和浮點(diǎn)值。
b) Relational operators
b)關(guān)系運(yùn)算符
They are used for comparison between two values. They return result as true or false.
它們用于兩個(gè)值之間的比較。 它們返回結(jié)果為true或false。
| Operator name | Operator |
| Less than | < |
| Less than or equal to | <= |
| Greater than | > |
| Greater than or equal to | >= |
| Equal to | == |
| Not equal to | != |
| 操作員姓名 | 操作員 |
| 少于 | < |
| 小于或等于 | <= |
| 比...更棒 | > |
| 大于或等于 | > = |
| 等于 | == |
| 不等于 | != |
c) Logical operators
c)邏輯運(yùn)算符
Used to combine two relational expression and they returns result as true or false.
用于組合兩個(gè)關(guān)系表達(dá)式,它們返回結(jié)果為true或false。
| 0 | 0 | 0 | 0 | 1 |
| 0 | 1 | 0 | 1 | 1 |
| 1 | 0 | 0 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 |
| 0 | 0 | 0 | 0 | 1個(gè) |
| 0 | 1個(gè) | 0 | 1個(gè) | 1個(gè) |
| 1個(gè) | 0 | 0 | 1個(gè) | 0 |
| 1個(gè) | 1個(gè) | 1個(gè) | 1個(gè) | 0 |
d) Bitwise operators
d)按位運(yùn)算符
They are used to perform operation on individual bits. They can be applied on char and int.
它們用于對單個(gè)位執(zhí)行操作。 它們可以應(yīng)用于char和int 。
| & | Ampersand | Bitwise AND |
| | | Pipe | Bitwise OR |
| ^ | Caret | Bitwise X OR |
| ~ | Tilde | Bitwise compliment |
| << | Double less than | Left shift operator |
| >> | Double greater than | Right shift operator |
| 和 | &符 | 按位與 |
| | | 管 | 按位或 |
| ^ | 插入符號 | 按位X OR |
| ? | 蒂爾德 | 按位贊美 |
| << | 少于兩倍 | 左移運(yùn)算符 |
| >> | 大于 | 右移運(yùn)算符 |
C Operator Precedence Table:
C運(yùn)算符優(yōu)先級表:
This page lists C operators in order of precedence (highest to lowest). Their associativity indicates in what order operators of equal precedence in an expression are applied.
本頁按優(yōu)先順序(從高到低)列出C運(yùn)算符。 它們的關(guān)聯(lián)性指示在表達(dá)式中應(yīng)用相同優(yōu)先級的運(yùn)算符的順序。
翻譯自: https://www.includehelp.com/c/basics-of-c-language.aspx
c語言語言教程0基礎(chǔ)
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的c语言语言教程0基础_C语言基础的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 许昌看输卵管炎最好的医院推荐
- 下一篇: CUL8R的完整形式是什么?