c語言語言教程0基礎_C語言基礎

c語言語言教程0基礎

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.

嘿,伙計們,我回來了第二篇有關C語言的文章。 希望您能讀完我以前的C語言文章-歷史,流行原因,特征,基本結構等 。 在這一篇中,我將介紹C語言的一些基本概念,即C語言中的變量,標記,運算符

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.

它們是在程序執行期間分配的臨時內存位置。 顧名思義,它是一個在程序執行期間其值可能會更改的實體。

Rules for variable name

變量名規則

  1. It does not have a space between characters.

    字符之間沒有空格。

  2. Collection of alphabets, digits, and underscore (_).

    字母,數字和下劃線(_)的集合。

  3. The first character should be either alphabet or underscore (_).

    第一個字符應為字母或下劃線(_)。

  4. No other special symbol except underscore (_).

    除下劃線(_)外,沒有其他特殊符號。

  5. Keywords cannot be used as variable name.

    關鍵字不能用作變量名。

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.

它告訴用戶聲明的變量的數據類型是什么或它可以保存的值的類型。

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 :

令牌包括:

  1. Keywords

    關鍵詞

  2. Identifier

    識別碼

  3. Constants

    常數

  4. String Constant

    字符串常量

  5. Operators

    經營者

  6. Special Symbols e.g: _ , @ , *

    特殊符號,例如:_,@,*

1) Keywords or Reserve words

1)關鍵字或保留字

These are those words whose meaning is already explained to the compiler.

這些是已經向編譯器解釋其含義的單詞。

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.

它們不能用作變量名,因為如果這樣做,則意味著我們正在為編譯器定義編譯器不允許的新含義。

2) Identifier

2)識別碼

They are the name given to programming elements such as array, function, variable. Same rules as of variable name.

它們是諸如數組,函數,變量之類的編程元素的名稱。 與變量名相同的規則。

3) Constant

3)常數

Entities whose value does not during the execution of a program.

其值在程序執行期間不存在的實體。

4) String constant

4)字符串常量

Collection of character enclosed by a double inverted comma. e.g.: "abc"

用雙反逗號括起來的字符的集合。 例如: “ abc”

5) Operators

5)運營商

They are used to perform arithmetic and logical operations by ALU.

它們由ALU用于執行算術和邏輯運算。

Example:

例:

 a+b

Here, a and b are operands and + is an operator.

在這里, a和b是操作數,而+是運算符。

C language has very rich operators. Many different types of operators are available in C language for different mathematical computations.

C語言具有非常豐富的運算符。 C語言提供了許多不同類型的運算符,用于不同的數學計算。

They are mainly of three types:

它們主要分為三種類型:

Types of operators

Operators itself is a separate topic which needs to be covered in detail.

運營商本身是一個單獨的主題,需要詳細介紹。

So, here we get started.

所以,我們開始。

Unary operators

一元運算符

They require only one operand for execution, it includes :

它們只需要一個操作數即可執行,其中包括:

  1. Unary minus

    一元減

  2. Bitwise compliment

    按位贊美

  3. Logical Not

    邏輯不

  4. Increment / Decrement

    增量/減量

  5. sizeof() operator

    sizeof()運算符

sizeof() Operator

sizeof()運算符

It is used to return the size of an operand. It can be applied on variable, constant, datatype.

它用于返回操作數的大小。 它可以應用于變量,常量,數據類型。

Syntax:

句法:

sizeof(operand);

Example:

例:

    int a=2, b;
b = sizeof(a);
//or
b = sizeof(int);
//or
b = sizeof(5);
printf("%d\n",b);
//All of the 3 three statements will give same output.

Ternary operators

三元運算符

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.

它們也稱為條件運算符。 對于這些運算符,我們需要3個操作數來執行。 用C語言只有一個三元運算符。

Syntax:

句法:

 expression_1  ? expression_2 : expression_3 ;

If expression_1 is true expression_2 gets executed, if false then expression_3.

如果expression_1為true,則執行expression_2 ,如果為false,則執行expression_3 。

Example:

例:

    int a=4 , b=7 , c;
c = ( a<7 ? a:b );
printf("%d\n", c );

Output

輸出量

 4

Since, a = 4, exp_1 is true and therefore exp_2 gets executed. So, c = a gets executed.

由于a = 4 , exp_1為true,因此exp_2被執行。 因此, c = a被執行。

Binary operators

二元運算符

i) Arithmetic operators

i)算術運算符

Operator nameOperator
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.

模運算符給出余數,除法運算符給出商。 除模數僅用于整數外,所有算術運算符均可用于整數和浮點值。

b) Relational operators

b)關系運算符

They are used for comparison between two values. They return result as true or false.

它們用于兩個值之間的比較。 它們返回結果為true或false。

Operator nameOperator
Less than<
Less than or equal to<=
Greater than>
Greater than or equal to>=
Equal to ==
Not equal to !=
操作員姓名 操作員
少于 <
小于或等于 <=
比...更棒 >
大于或等于 > =
等于 ==
不等于 !=

c) Logical operators

c)邏輯運算符

Used to combine two relational expression and they returns result as true or false.

用于組合兩個關系表達式,它們返回結果為true或false。

ABA && BA || B!A
00001
01011
10010
11110
一個 A && B A || 乙 !一個
0 0 0 0 1個
0 1個 0 1個 1個
1個 0 0 1個 0
1個 1個 1個 1個 0

d) Bitwise operators

d)按位運算符

They are used to perform operation on individual bits. They can be applied on char and int.

它們用于對單個位執行操作。 它們可以應用于char和int 。

OperatorsSymbol nameMeaning
&AmpersandBitwise AND
|PipeBitwise OR
^CaretBitwise X OR
~TildeBitwise compliment
<<Double less thanLeft shift operator
>>Double greater thanRight shift operator
經營者 符號名稱 含義
&符 按位與
| 按位或
^ 插入符號 按位X OR
? 蒂爾德 按位贊美
<< 少于兩倍 左移運算符
>> 大于 右移運算符

C Operator Precedence Table:

C運算符優先級表:

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.

本頁按優先順序(從高到低)列出C運算符。 它們的關聯性指示在表達式中應用相同優先級的運算符的順序。

C Operator Precedence Table

翻譯自: https://www.includehelp.com/c/basics-of-c-language.aspx

c語言語言教程0基礎

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/377151.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/377151.shtml
英文地址,請注明出處:http://en.pswp.cn/news/377151.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

《MySQL——臨時表》

內存表與臨時表區別 臨時表&#xff0c;一般是人手動創建。 內存表&#xff0c;是mysql自動創建和銷毀的。 內存表&#xff0c;指的是使用Memory引擎的表&#xff0c;建表語法&#xff1a;create table ... engine memeory 表的數據存在內存里&#xff0c;系統重啟后會被清…

android中ActionBar的幾個屬性

actionBar.setHomeButtonEnabled //小于4.0版本的默認值為true的。但是在4.0及其以上是false&#xff0c;該方法的作用&#xff1a;決定左上角的圖標是否可以點擊。沒有向左的小圖標。 true 圖標可以點擊 false 不可以點擊。 actionBar.setDisplayHomeAsUpEnabled(true) //…

drei

模擬9 T3 &#xff08;COGS上也有&#xff0c;鏈接http://218.28.19.228/cogs/problem/problem.php?pid1428&#xff09; 題目描述 輸入a&#xff0c;p&#xff0c;求最小正整數x&#xff0c;使得a^x mod p 1。 分析 神奇的歐拉定理&#xff08;對于gcd&#xff08;a&#xf…

《MySQL——group by使用tips》

1、如果對group by語句結果沒有排序要求&#xff0c;在語句后面加order by null 2、盡量讓group by 過程用上索引&#xff0c;確認方法是explain結果里沒有Using temporary 和Using filesort 3、如果group by 需要統計的數據量不大&#xff0c;盡量只使用內存臨時表&#xff…

css中變量_CSS中的變量

css中變量CSS | 變數 (CSS | Variables) CSS variables allow you to create reusable values that can be used throughout a CSS document. CSS變量允許您創建可在CSS文檔中使用的可重用值。 In CSS variable, function var() allows CSS variables to be accessed. 在CSS變…

位圖像素的顏色 攜程編程大賽hdu

位圖像素的顏色 Time Limit: 2000/1000 MS (Java/Others) MemoryLimit: 32768/32768 K (Java/Others) Total Submission(s): 0 Accepted Submission(s): 0 Problem Description 有一個在位圖上畫出矩形程序&#xff0c;一開始位圖都被初始化為白色&#xff08;RGB顏色表示…

《MySQL——InnoDB與Memory以及臨時表》

InooDB與Memory 數據組織方式不同&#xff1a; InnoDB引擎把數據放在主鍵索引上&#xff0c;其他索引上保存的是主鍵id。為索引組織表Memory引擎把數據單獨存放&#xff0c;索引上保存數據位置。為堆組織表 典型不同處&#xff1a; 1、InnoDB表的數據總是有序存放的&#x…

Oracle 用戶 profile 屬性 轉

--查看profile 內容 select * from dba_profiles where profilePF_EAGLE; --查看用戶的profiles select username,profile from dba_users; --查看是否啟用動態資源限制參數 SHOW PARAMETER RESOURCE_LIMIT; --啟用限制 ALTER SYSTEM SET RESOURCE_LIMITTRUE SCOPEBOTH; --創建…

CUL8R的完整形式是什么?

CUL8R&#xff1a;稍后再見 (CUL8R: See You Later) CUL8R is an abbreviation of "See You Later". CUL8R是“稍后見”的縮寫 。 It is an expression, which is commonly used in messaging or chatting on social media networking sites like Facebook, Yahoo M…

SuperSpider——打造功能強大的爬蟲利器

SuperSpider——打造功能強大的爬蟲利器 博文作者&#xff1a;加菲 發布日期&#xff1a;2013-12-11 閱讀次數&#xff1a;4506 博文內容&#xff1a; 1.爬蟲的介紹 圖1-1 爬蟲&#xff08;spider) 網絡爬蟲(web spider)是一個自動的通過網絡抓取互聯網上的網頁的程序&#xf…

《MySQL——關于grant賦權以及flush privileges》

先上總結圖&#xff1a; 對于賦予權限或者收回權限還是創建用戶&#xff0c;都會涉及兩個操作&#xff1a; 1、磁盤&#xff0c;mysql.user表&#xff0c;用戶行所有表示權限的字段的值的修改 2、內存&#xff0c;acl_users找到用戶對應的對象&#xff0c;將access值修改 g…

對Spring的理解

1、Spring實現了工廠模式的工廠類&#xff0c;這個類名為BeanFactory實際上是一個接口&#xff0c;在程序中通常BeanFactory的子類ApplicationContext。Spring相當于一個大的工廠類&#xff0c;在其配置文件中通過<bean>元素配置用于創建實例對象的類名和實例對象的屬性。…

Java中的null是什么?

As we know null is an important concept in every language not only in Java but here we will study various factors regarding null. 我們知道null在每種語言中都是重要的概念&#xff0c;不僅在Java中&#xff0c;在這里我們還將研究有關null的各種因素。 null is a ver…

《MySQL——分區表小記》

分區表的組織形式 以年份為分割方式&#xff0c;對表進行分割&#xff1a; CREATE TABLE t (ftime datetime NOT NULL,c int(11) DEFAULT NULL,KEY (ftime) ) ENGINEInnoDB DEFAULT CHARSETlatin1 PARTITION BY RANGE (YEAR(ftime)) (PARTITION p_2017 VALUES LESS THAN (201…

實戰Windows下安裝boost

Boost大部分組件無需編譯可直接包含頭文件使用&#xff0c;但還有一些庫需要編譯成靜態庫或動態庫才能使用。可使用下文將提到的bjam工具&#xff1a;bjam --show-libraries 查看必須編譯才能使用的庫。 編譯安裝環境&#xff1a;Win7&#xff0c;VS2008(msvc-9.0) 1. 下載boos…

postgresq dur_DUR的完整形式是什么?

postgresq dur杜爾(DUR)&#xff1a;您還記得嗎&#xff1f; (DUR?: Do You Remember?) DUR? is an abbreviation of "Do You Remember?". DUR&#xff1f; 是“您還記得嗎&#xff1f;”的縮寫。 。 It is an expression, which is commonly used in messaging…

gsettings-desktop-schemas : 破壞: mutter (< 3.31.4) 但是 3.28.4-0ubuntu18.04.2 正要被安裝解決方案

完整報錯&#xff1a; dyydyy-Lenovo-ThinkBook-14-IIL:~$ sudo apt install build-essential 正在讀取軟件包列表... 完成 正在分析軟件包的依賴關系樹 正在讀取狀態信息... 完成 有一些軟件包無法被安裝。如果您用的是 unstable 發行版&#xff0c;這也許是 因…

程序內存檢測

本文參考自&#xff1a;http://www.cnblogs.com/hebeiDGL/p/3410188.html static System.Windows.Threading.DispatcherTimer dispacherTimer;static string total "DeviceTotalMemory";static string current "ApplicationCurrentMemoryUsage";static s…

動態規劃天天練1

本來很久以前就打算每天練一道動態規劃題的&#xff0c;但每每由于作業太多而中斷&#xff0c;現在終于停課了......廢話不多說&#xff0c;第一道題就給了我迎頭一棒&#xff0c;不僅想了很久&#xff0c;連題解都看了很久。。。水平相當不足啊啊&#xff0c;不多說廢話&#…

AAS的完整形式是什么?

AAS&#xff1a;活著和微笑 (AAS: Alive And Smiling) AAS is an abbreviation of "Alive And Smiling". AAS是“活著和微笑”的縮寫 。 It is an expression, which is commonly used in messaging or chatting on social media networking sites like Facebook, Y…