主要普及c語言的基本語法,本文預設初看的人啥也不懂,如果有程式設計基礎請略過
下面來仔細看一下c編輯器預設給我們生成的**
執行後可以在控制台看見#include
int main (
)
hello word
於是可以做以下嘗試根據程式的變化來逐一了解**的含義
注釋printf(「hello word\n」);
在第二行新增乙個printf(「hello word\n」);#include
int main (
)
在第二行新增int main (){};#include
printf
("hello word\n");
int main (
)
修改第三行int 為intt#include
int main ();
int main (
)
注釋第一行#include
intt main (
)
做完以上嘗試你會發現除了第乙個嘗試可以正常通過編譯,其他嘗試是無法通過編譯的//#include
intt main (
)
以下是每種嘗試會出現的問題你會發現程式可以通過編譯,但是無法控制台輸出是下面這樣的
當你嘗試第二個操作的時候會發現編輯器會報錯process finished with exit code 0
//很顯然沒有輸出 hello word
編輯器會報乙個這樣的錯誤c:\main.c:2:8: error: expected declaration specifiers or '...' before string constant
printf(
"hello, world!\n");
^//也就是在main函式的上面不能寫輸出語句
繼續報錯c:\main.c:3:5: error: redefinition of 'main'
int main();
^
接下來…c:\users\likexian\clionprojects\ke03\main.c:2:1: error: unknown type name 'intt'
intt main(
)符號外面
乙個mian.c檔案有且只能有乙個main函式
函式返回的資料型別必須是定義好的
printf 函式屬於 #include 這個標準庫
經過上面的一系列嘗試,現在已經能大概摸清楚c語言寫法的基本套路了
接下來說什麼呢
說幾點注意事項吧
c語言的寫法
//當然沒人要求你必須這樣寫main函式
intmain()
//你可以這樣寫,也可以執行成功
intmain()
//但是這樣寫就得祈禱接手專案的人永遠不會知道你的詳細位址和** and email
先這樣吧…
C語言教程 迴圈
c語言中有2種最常用的迴圈語句 while迴圈 和for 迴圈。while迴圈 while loop while 表示式 程式塊還有乙個變種 do while迴圈,do while 表示式 只要while裡得到表示式是真的,就一直執行程式塊的語句。for迴圈 for loop for 表示式1 表示...
C語言教程 三 C語言的資料型別
一 變數與常量資料 1 include2 intmain 3 其中year是乙個int型別的變數,而2014是常量,即乙個數字。變數的定義 在程式中使用的變數名 函式名 標號等統稱為識別符號。除庫函式的函式名由系統定義外,其餘都由使用者自定義。c規定,識別符號只能是字母 a z,a z 數字 0 9...
Golang 語言 教程
目錄 golang入門指南 golang教程,設定工作區 go mods hello world golang教程 變數 golang教程 資料型別 數字,字串和布林值 陣列,切片和對映 golang教程 型別轉換 條件語句 if else switch case 迴圈指標 函式可變函式 方法,結構...