The game in the classics: Chapter One hello,world! of C + +

Source: Internet
Author: User
Tags what header

Original creation Place: http://www.cnblogs.com/Alandre/sediment brick slurry Carpenter hope reprint, keep abstract, thank you!

Figure 1.1 "We hit it with stones" from the Beauty of mathematics

Among them, he uses the strange call and the action tells the small partner this behavior, is called the procedure. Only a partner who understands this will pick up a rock and throw it together. But compared to computers, computers are "dumb", and in order to interpret them like computers, we need a language that is precisely defined by a particular grammar. That's the programming language, like C + +.

1.2 Classic Taste "hello,world! “

This is the classic example of a screen that outputs "hello,world! “:

12345678 #include <iostream>using namespace std;int main(){    cout << "Hello,World!\n";    return0;}

Run Results: Print hello,world! Then, the following new line. One cursor is at the beginning of the next line.



Figure 1.2 hello,world! output

In the program, the main work of the code:

1 cout << "Hello,World!\n";

cout is a standard output stream that can be displayed on the screen using the << operator. Naturally, this is the first time you see abbreviations, cout:character outputstream abbreviations. At first it won't fit, but when you meet a lot of abbreviations, you'll fall in love with him.

First line:

1 #include <iostream>

He's an instruction, and this specifically lets us use the standard C + + streaming I/O functionality. Here, we used the cout and its operator << Additionally, files that are included with # include usually have the suffix. h, which is called the header file or header. We basically use C + + to provide our own source code for various functions. For example above, we need what function to introduce what header file.

Program Entry:

1234 intmain(){    return0;}

Everyone knows a program to tell the computer where to start execution, C + + Each program must have a main function. A function is basically a set of instructions, also known as a sequence of instructions, and the computer executes in the order it was originally ordered. A function usually includes:

    • Return type: This is int, which is used to specify the return result type.
    • Name: This is main
    • Parameter list: null here, if there are parameters, will be written in ()
    • function body: {} The statement in which the function executes is written.

The end of the program:

1 return0;

You know, the main function is called by the system, and naturally we need to tell the system when it ends. The return value can be used to check whether the program was successful, particularly in some systems (Unix/linux). A 0 returned by main () indicates that the program terminated successfully.

1.3 Beyond the program code you can't see: Compiling links

"Hello,world! "The program runs through the C + + programming language. In its conversion from a human readable format to something that the computer can understand, this process requires a program that becomes a "compiler".

What is a compiler?

Wikipedia says that the compiler (Compiler) is a computer program that converts source code written in one programming language (the original language) into another programming language (the target language). Its main purpose is to facilitate people to write, read, maintain the advanced computer language written by the source Code program, translated into a computer can read, run the low-order machine language program, that is, executable files. As a metaphor, a voice-activated light, if we want to say "turn on the Lights", the light is clearly not aware of the meaning of this sentence. Its world is: "There is a voice I will light." Then your servant shouted and the light was on. This servant's work is the compiler's program principle.

The main workflow for a modern compiler is as follows: source code → preprocessor (preprocessor) → compiler (compiler) → assembler (assembler) → object Code → Linker (Linker) → executable file (executables). Therefore, readable writable is called the source code, and the computer can execute the target code. In the coming days, you will come into contact with this friend, he is very strict. But remember, the compiler is your best friend in programming. Below we show the process of the program:

Figure 1.3 hello,world! 's Life

The game in the classics: Chapter One hello,world! of C + +

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.