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

Source: Internet
Author: User
Tags what header

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

"Program design to learn through the practice of writing programs"-brian Kernighan1.1 Procedures

What is a program? Simply put, to make a computer work, you need to tell it how to do it in tedious detail. The description of what to do is the program. Programming is the process of writing and testing how to do it. Wikipedia says a program is like a braised pork recipe (program) written in Chinese (programming language) that guides people who understand Chinese and cooking techniques (architecture) to do this dish. To make an image metaphor, in a sense of life, you see the program. Stone Age, "we hit it with stones." It's a program.

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! “:

#include <iostream>using namespace Std;int main () {cout << "hello,world!\n"; return 0;}

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:

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:

#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:

int main () {return 0;}

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:

    return 0;

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

1.4 The first chapter summary and ponder

hello,world! It doesn't matter, it's important that we are familiar with basic ideas and tools. Once saw through the recipes, became the chef. A writer or other who has ever been through history. Diligence, concentration, perseverance. C + + is not difficult.

If the above articles or links are helpful to you, don't forget to click the "Like a" button on the article button or in the bottom right corner of the page. You can also click on the right side of the page "share" hover button oh, let more people read this article

Here is the PDF, to be downloaded please open: (http://files.cnblogs.com/Alandre/Cplusplus01.pdf)

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.