B1 中級 英國腔 918 分類 收藏
開始影片後,點擊或框選字幕可以立即查詢單字
字庫載入中…
回報字幕錯誤
Hi, my name is Alex and this is the first in a series of videos on becoming a better computer programmer.
For this particular video we're going to be focusing on the C programming language,
which is commonly used at universities as a teaching tool and has much in common with most languages used in commercial development.
At this point I am assuming zero knowledge of programming and C in general,
so obviously feel free to move to a more advanced video as your needs require.
By way of introduction, let me say I've been programming as a hobbyist and a professional for the best part of 13 years now,
having intially started with Basic before teaching myself C.
I now work for the market leader in financial analytics software,
still using the C family of languages on a day-to-day basis.
Whenever you encounter a new programming language you're invariably shown what's called a 'Hello World' program,
which is generally the simplest meaningful program that can be written in a language.
On screen now is the 'Hello World' program in C which we're going to pick apart over the next few minutes.
You can take this program and compile it in any C or C++ compiler,
such as Microsoft Visual Studio on Windows, which I'm using here.
The first thing to note about C is it's a procedural programming language.
This means the program is arranged as functions while control and execution flows from one function to another.
Your program is read and executed line-by-line by the computer.
You may be wondering how the computer knows where to start this execution,
and the answer is that when you compile your program it looks for a function named main, as this one is here.
It takes arguments, signified by the words in brackets, which are inputs from the command line
and returns an integer - signified by int. Don't worry if you don't understand these terms yet.
Note that you can have only one main function in a program or you won't be able to compile it.
Each function, including the main function, must be included in what's called a block, signified by these curly braces.
The code between these outer braces constitutes what's called the scope of the function.
This has implications later on when you declare variables
which only exist within the scope of a function, or a subsection of a function.
Again, don't worry about this too much now, and instead remember
that you can identify the scope of a block of code with these curly braces.
Functions also end in a return statement. If you're not returning anything specific
- that is, the function returns type void - you can skip the return statement altogether,
but it will just be implied by the compiler. When learning C,
you should use the return statement every time just to keep track of what you're doing in your program.
In this case, our function returns a 0; returning a zero from a main function of a program signifies
to the operating system that the program has terminated without errors,
whereas any other number would be returned as an error code. These codes enable you to have multiple programs working together,
reading and processing each others' output codes.
This is relatively common practice in industry.
The last part of this program, and the most important part, is the printf() statement.
Printf is another function which is defined by the C language. It displays a message to the standard output device.
Thus if you run this program in a command line, it will print to that.
There's a couple of key things to note about the way printf is used.
Firstly, we have to tell the compiler where to find Printf. This is done by the include statement at the top of the program
stdio (standard Input/output) is part of the standard C library
and contains the necessary information about this function.
Secondly, the section included in the brackets after printf is what's known as an argument.
Functions can take any number of arguments, or no arguments like our main function, signified by the word void.
For the printf function, the argument is, as you've probably guessed,
what you want printed to the screen. Make sure when you pass a string of characters like this
to use double quotation marks, not single, for reasons we'll cover in the next video.
The backslash-n is what's known as a special 'escape character' and tells the printf function
we want a new line after this point.
As a quick note, this system("PAUSE") statement simply tells the computer to wait for the user
to press a key before continuing in the program. I've inserted it here so that when
when we run our program, the output window will stay open until we hit a key,
allowing us to see what our program is doing.
Finally, notice that the end of this line, and the end of the return statement, have a semicolon.
Forgetting this is a key mistake you'll find happens a lot when learning C,
and it causes problems because the compiler won't know where your lines end.
If you find a program isn't compiling, always double check you put semicolons at the end of all your lines,
notwithstanding a few exceptions we'll cover later.
And that's all there is to it. We can now compile and run this program, and see the output here.
For now, try creating this program yourself, and try putting different message in the program
and see how the output changes. Of course, feel free to post any questions afterwards.
Thank you.
提示:點選文章或是影片下面的字幕單字,可以直接快速翻譯喔!

載入中…

C程式設計的首部曲 (Hello World in C Programming Language)

918 分類 收藏
Jjli Li 發佈於 2016 年 6 月 5 日    Jjli Li 翻譯    Mandy Lin 審核
看更多推薦影片
  1. 1. 單字查詢

    在字幕上選取單字即可即時查詢單字喔!

  2. 2. 單句重複播放

    可重複聽取一句單句,加強聽力!

  3. 3. 使用快速鍵

    使用影片快速鍵,讓學習更有效率!

  4. 4. 關閉語言字幕

    進階版練習可關閉字幕純聽英文哦!

  5. 5. 內嵌播放器

    可以將英文字幕學習播放器內嵌到部落格等地方喔

  6. 6. 展開播放器

    可隱藏右方全文及字典欄位,觀看影片更舒適!

  1. 英文聽力測驗

    挑戰字幕英文聽力測驗!

  1. 點擊展開筆記本讓你看的更舒服

  1. UrbanDictionary 俚語字典整合查詢。一般字典查詢不到你滿意的解譯,不妨使用「俚語字典」,或許會讓你有滿意的答案喔