I read the code series (1) -------- Hello, World!

zhaozj2021-02-16  92

// Original article, keep everything right, reprint, please indicate the source

// Author: ji_gr

Preface: I read the code series attempt to explore some C details through some classic code, and thereby discover more deeper things. I always think that as a good programmer, there should be the essence of the essence, but also have a habit of grasp the code details! // The Hello World Program.

// Source: http://www.research.att.com/~bs/hello_world.c

// Author: bs@research.att.com

#include

Int main () {std :: cout << "Hello, World! / N";

// Note That "Return 0;" ISN't Required IN ISO C debug: Under VS.NET, you want to include a header file: #include "stdafx.h", debug pass. This procedure is simple to follow, and everyone will say hello! However, there is still a problem worth exploring: Question 1:

What about suffix. H?

A: The standard says not .h, because different compiler suffixes are different.

Question 2: Remember the teacher said, # include

All the same as #include "filename.h", is it? Since it is the same as two?

A: There is a difference. "C primer" said: <> is used to include the header file of the standard library and without suffixes. ", Is used to include the compiler or programmer's own header file.

Let's take a few tests: under VS.NET:

#include "stdafx" /// wrong, no

#include

Wrong, no

#include

OK!

#include "iostream" //?? can! Oh, it is best not to do this.

Did you see what is it? In fact, we should adhere to this principle: #include

, #include "self_head_file.h".

Question three: Note That "Return 0;" ISN't Required In ISO C ??? Standard, Return 0; can you not write? A: When you don't write, but still write it, it is not!

Question 3: Simple, write this program again! A: OK! // I read the code series (1) -------- Hello, World! // The code below is professional? #include

Using namespace std; // std is of course here, save std ::

int main ()

{

Cout << "Hello, World! << endl; // endl and '/ n' are different, as for difference? Again!

RETURN 0; // Standard does not require? What happened to I wrote, don't write how others know. It is clear!

}

转载请注明原文地址:https://www.9cbs.com/read-11651.html

New Post(0)