C語言丨入門筆記-4(含計算機英語)

2021-02-19 特斯貝爾TU

It uses an array to hold a character string.

用數組(array)儲存字符串(character string)。

 

It uses the %s conversion specification to handle the input and output of the string.

使用%s轉換說明來處理字符串的輸入和輸出。

 

A character string is a series of one or more characters. Double quotation marks inform the compiler that they enclose a string, just as single quotation marks identify a character.

字符串(character string)是一個或多個字符的序列。雙引號僅告知編譯器它括起來的是字符串,正如單引號用於標識單個字符一樣。

 

Strings in C are always stored with this terminating null character. The presence of the null character means that the array must have at least one more cell than the number of characters to be stored.

C中的字符串一定以空字符結束,這意味著數組的容量必須至少比待存儲字符串中的字符數多1。

 

An array is an ordered sequence of data elements of one type.

數組是同類型數據元素的有序序列。

 

char name[40];

The brackets after name identify it as an array. The 40 within the brackets indicates the number of elements in the array. The char identifies the type of each element.

char name[40];

name後面的方括號表明這是一個數組,方括號中的40表明該數組中的元素數量。char表明每個元素的類型。

 

After scanf() starts to read input, it stops reading at the first whitespace (blank, tab, or newline) it encounters. In general, scanf() is used with %s to read only a single word, not a whole phrase, as a string.

scanf() 在遇 到第1個空白(空格、制表符或換行符)時就不再讀取輸入。一般而言,根據%s轉換說明,scanf()只會讀取字符串中的一個單詞,而不是一整句。

 

The strlen() function gives the length of a string in characters. It takes one byte to hold one character. The sizeof operator gives the size of things in bytes.

strlen() 函數給出字符串中的字符長度。1 字節儲存一個字符。sizeof運算符,以字節為單位給出對象的大小。

 

The string.h file contains function prototypes for several string-related functions, including strlen().

string.h頭文件包含多個與字符串相關的函數原型,包括strlen()。

 

strlen() gives you the exact number of characters(including spaces and punctuation) in the string. The sizeof operator gives you a number one larger because it also counts the invisible null character used to end the string.

用strlen()得出的是字符串中的字符數(包括空格和標點符號)。然而,sizeof運算符給出的數更大,因為它把字符串末尾不可見的空字符也計算在內。

 

The C99 and C11 standards use a %zd specifier for the type used by the sizeof operator. This also applies for type returned by strlen().

C99 和 C11 標準專門為 sizeof 運算符的返回類型添加 了%zd 轉換說明,這對於strlen()同樣適用。

 

sizeof(char)

sizeof(float)

sizeof name

sizeof 6.28

Whether you use parentheses depends on whether you want the size of a type or the size of a particular quantity. Parentheses are required for types but are optional for particular quantities.

圓括號的使用與否取決於運算對象是類型還是特定量。運算對象是類型時,圓括號必不可少,但是對於特定量,可有可無。

 

symbolic constant 符號常量

Suppose you have used a constant in several places, and it becomes necessary to change its value. Then you only need to alter the definition of the symbolic constant, rather than find and change every occurrence of the constant in the program.

假設程序中的多處使用一個常量,有時需要改變它的值。如果程序使用符號常量,則只需更改符號常量的定義,不用在程序中查找使用常量的地方,然後逐一修改。

 

#define TAXRATE 0.015

When your program is compiled, the value 0.015 will be substituted everywhere you have used TAXRATE. This is called a compile-time substitution. Such defined constants are often termed manifest constants.

編譯程序時,程序中所有的TAXRATE都會被替換成0.015。這一過程被稱為編譯時替換(compile-time substitution)。這樣定義的常量也稱為明示常量 (manifestconstant)。

 

#define NAME value

No semicolon is used because this is a substitution mechanism handled by the preprocessor, not a C statement. Why isTAXRATE capitalized? It is a sensible C tradition to type constants in uppercase. Then, when you encounter one in the depths of a program, you know immediately that it is a constant, not a variable.

末尾不用加分號,因為這是一種由預處理器處理的替換機制。為什麼 TAXRATE 要用大寫?用大寫表示符號常量是 C 語言一貫的傳統。這樣,在程序中看到全大寫的名稱就立刻明白這是一個符號常量,而非變量。

 

C90 added a second way to create symbolic constants—using the const keyword to convert a declaration for a variable into a declaration for a constant: 

const int MONTHS = 12; // MONTHS a symbolic constant for 12

This makes MONTHS into a read-only value.

C90標準新增了const關鍵字,用於限定一個變量為只讀。

 

The C header files limits.h and float.h supply detailed information about the size limits of integer types and floating types, respectively. Each file defines a series of manifest constants that apply to your implementation.

C頭文件limits.h和float.h分別提供了與整數類型和浮點類型大小限制相關的詳細信息。每個頭文件都定義了一系列供實現使用的明示常量。

 

Although printf() is an output function and scanf() is an input function, both work much the same, each using a control string and a list of arguments.

雖然printf()是輸出函數,scanf()是輸入函數,但是它們的工作原理幾乎相同。兩個函數都使用格式字符串和參數列表。

 

The instructions you give printf() when you ask it to print a variable depend on the variable type. We have used the %d notation when printing an integer and the %c notation when printing a character. These notations are called conversion specifications because they specify how the data is to be converted into displayable form.

請求printf()函數列印數據的指令要與待列印數據的類型相匹配。列印整數時使用%d,列印字符時使用%c。這些符號被稱為轉換說明(conversion specification),它們指定了如何把數據轉換成可顯示的形式。

 

You can modify a basic conversion specification by inserting modifiers between the % and the defining conversion character.

在%和轉換字符之間插入修飾符可修飾基本的轉換說明。

 

the field width 欄位寬度

the number of digits to the right of the decimal 小數點後面的位數

 

If you use scanf() to read a value for one of the basic variable types, precede the variable name with an & .If you use scanf() to read a string into a character array, don’t use an &.

如果用scanf()讀取基本變量類型的值,在變量名前加上一個&;如果用scanf()把字符串讀入字符數組中,不要使用&。

 

The * serves quite a different purpose for scanf(). When placed between the % and the specifier letter, it causes that function to skip over corresponding input.

scanf()中*的用法與printf()不同。把*放在%和轉換字符之間時,會使得scanf()跳過相應的輸入項。

 

相關焦點

  • C語言丨入門筆記-2(含計算機英語)
    計算機bit(binary digit)是二進位位簡稱「位」。最小的存儲單元是位(bit),可以儲存0或1(或者說,位用於設置「開」或「關」)。一個二進位位包含的信息量稱為一比特。 字節(byte)[baɪt] 是常用的計算機存儲單位。對於幾乎所有的機器,1位元組均為8位。
  • C語言丨入門筆記-3(含計算機英語)
    在C語言中,字符型 char、短整型 short、整型 int、長整型 long、超長整型 long long、有符號類型 signed 以及無符號類型 unsigned 都是整數類型。 INT_MINint類型所能表示的最小值;INT_MAXint類型所能表示的最大值。
  • 門外漢入門級C語言學習筆記——從東拉西扯中硬核回歸
    筆記主要摘自於:華章科技 《手把手教你學C語言》於是我做了些筆記給與我當初同樣迷茫的電腦編程小白——我們一起從0學習程式語言——C語言。不誇張的說——C是任何語言的基礎。C是一門程式語言,跟計算機對話。為什麼偏偏是C?可是為什麼很多人在說這句話呢?我就是不懂啊!
  • 「C語言從入門到入土」必備C語言基礎筆記整理
    一、C語言1、什麼是C語言?C語言是人寫機器看的一種語言。C語言是高級語言中的低級語言。C語言貼近硬體。C語言的入門學習比較簡單。彙編語言——>B語言——>C語言2、C語言的特性首先C語言就是你的女朋友。無論你讓它幹什麼,它絕對不會自己找到方法。
  • c語言入門教程
    導讀:隨著微型計算機的日益普及,C語言成為世界上最流行、使用最廣泛的高級程序設計語言之一。下面我們就一起來了解一下C語言的世界是什麼樣子的吧。本文引用地址:http://www.eepw.com.cn/article/272684.htm  C語言是一種電腦程式設計語言,它既具有高級語言的特點,又具有彙編語言的特點。它由美國貝爾研究所的D.M.Ritchie於1972年推出,它可以作為工作系統設計語言,編寫系統應用程式。
  • 《C語言入門指南》上篇
    話所在前面:《C語言入門指南》,全文分為3篇。此為上篇,涵蓋知識點為:發展史、快速入門、程序運行機制、基礎知識、常量、運算符、二進位和位運算、程序的控制結構、枚舉,上篇全文共計20000餘字,適用初學者入門C語言,非初學者也可以通過本文複習C語言相關知識點,強化記憶!十三發布這篇筆記也是為了複習C語言!
  • 大學生計算機二級考試C語言中的函數入門詳解
    C語言計算機二級考試必考考點之函數入門詳解一般來說理科生的大學生有一門必修課是編程,而想要從事軟體開發的人員,沒有C語言基礎是不行的。而C語言中比較重要的部分就是函數。今天這次課程我們從基礎的函數講起,教你輕鬆入門C語言。算法是什麼?什麼是算法,這個就有點像我們學習數學的時候的計算了。比如你在排列組合中需要計算5!,但是,你並不知道這個5!是什麼意思和含義,那麼你將計算不出來。
  • Golang入門筆記-03-語言基本數據類型
    1const (2 a = 1003 b // b 的值為 1004)1const (2 a = itoa // a 的值為 03 b // b 的值為 14 c // c 的值為 25)我們來看一個例子: 1package
  • C語言入門基礎知識大全
    用一個簡單的c程序例子,介紹c語言的基本構成、格式、以及良好的書寫風格,使小夥伴對c語言有個初步認識。2、main()——在c語言中稱之為「主函數」,一個c程序有且僅有一個main函數,任何一個c程序總是從main函數開始執行,main函數後面的一對圓括號不能省略。3、被大括號{ }括起來的內容稱為main函數的函數體,這部分內容就是計算機要執行的內容。
  • 學習c語言筆記——C庫函數printf()
    c語言中的printf是什麼來的?」。我答:「它是一個函數,主要用來輸出運算結果。」 ,下面就給大家介紹C庫函數printf()使用方法。下面我們通過一個調用c庫函數的c語言案例來說明printf()函數的使用方法,如c語言1。
  • 《C語言入門指南》中篇
    話所在前面:《C語言入門指南》,全文分為3篇。
  • C語言入門教程(一)
    C語言入門教程(一):輸入輸出函數、程序中的數據實驗環境Ubuntu 16.04 終端gcc
  • 萬字整理,C語言最全入門筆記!
    另外 c語言int的取值範圍在於他佔用的字節數 ,不同的編譯器,規定是不一樣。ANSI標準定義int是佔2個字節,TC是按ANSI標準的,它的int是佔2個字節的。但是在VC裡,一個int是佔4個字節的。浮點數據是指帶小數的數字。生活中有很多信息適合使用浮點型數據來表示,比如:人的體重(單位:公斤)、商品價格、圓周率等等。
  • c語言50本電子書
    C Primer Plus(第五版)中文版.pdfC專家編程.pdfC和C++內存管理.pdfC和指針.pdfC和指針(第二版).pdfC外掛編寫深究4.3.pdfC大綱[學習庫www.xuexi111.com].pdfC標準庫-中文.pdfC程式設計師面試100題.pptC經典算法大全
  • C語言入門學習視頻教程(完整版)
    免費C語言入門學習視頻教程,C語言是一種通用的、過程式的程式語言,廣泛用於系統與應用軟體的開發
  • c語言入門之安裝code::blocks
    C語言是普適性最強的一種電腦程式編輯語言,它不僅可以發揮出高級程式語言的功用,還具有彙編語言的優點。工欲善其事必先利其器要學習c語言,第一步就是安裝一款c語言程序設計的開發工具。這裡分步說明著名的Code::Blocks安裝過程。
  • C 語言程序設計---入門篇
    從本篇文章開始,我將分享 C 系列,將 C 語言的方方面面,從最基礎的語法帶領大家入門
  • 零基礎看得懂的C語言入門教程
    此次編寫計劃編寫一個快速入門的系列以及另一個全方面學習C語言的系列。快速入門系列以輕鬆、愉悅的方式編寫,並且剝離了入門階段極少使用的技術及概念,通過最「接地氣」的方式使剛入門的新手學習到最符合當前階段的知識,計劃閱讀時長為3小時即可完成C語言關鍵內容的掌握,並且達到期末不掛科的水平。
  • 嚴蔚敏數據結構C語言版課後習題答案及筆記
    向然學習資料網為同學們提供嚴蔚敏數據結構C語言版課後習題答案及筆記
  • 我一 jiao 踹開了 C 語言的大門
    老讀者都知道了,我妹今年上大一,學校安排的程式語言是 C 語言,這對於一個初學編程的小白來說,並不容易!作為她親哥的我,肩膀上抗著巨大的責任,那就是盡全力幫助她入門。前段時間為了她專門調研了一波 IDE,最後我比較鍾情 Visual Studio Code,輕量級,高顏值。