C Language Introductory Learning tutorial -2-hello world!

Source: Internet
Author: User

From here on, I will lead you small white, start programming ...

The first C-language program Hello world! :

1 #include "stdio.h" //Include header file

2 int main () //define Mian function

3 {

4 printf("Hello world!"); //Output string

5 return 0; //Return 0

4?

Well, we can clearly see that this program has a total of 4 parts: contains header file → define main function → output Holle world!→ return.

then, we will follow this step, first contains the header file:#include "stdio.h", in the C language, there is a kind of thing called the prefabricated instruction, the definition of the pre-order is at the beginning of the program by the "#" code, except this # Include directives, as well as #define and so on. How do we understand the prefabricated directives? We can understand this, the company's Xiao Wang is my subordinate, and then one day, I let him go to print some information, and then there is a bunch of information, specifically print Which? Xiao Wang made a difficult case, so I told him to print the employee payroll.

So, in this process, let Xiao Wang to print the information is the instruction, and the specific print "Employee Salary table" is the parameter of the command.

The include is the directive, and "stdio.h" is the parameter to the include directive.

Finally, the purpose of this include directive is to insert a header file from a compiler header file library into the include directive.

To explain what a header file is, the header is actually a library of functions provided by Microsoft (Microsoft) to programmers. It's a little hard to explain ... Some functions are defined in these header files, and we can call these functions to do what we need after we include the header files in our program. (Then how do we tell if a file is a header file?) Actually very simple, look at the file suffix name, the suffix ". h" File is the header file. )

And, the header file in the compiler's header file is thousands, why do we only include the stdio.h header file in the first program Hello World? Because, in our this Hello world! In the program (in the curly braces below the main function, the contents of this curly brace are the main program of our program, in the C language this part is called the function body) only a printf () function is used, and this function is defined in the "stdio.h" header file.

Then the 2nd line:int main (). This line is defined by the main function, in the C language there is a string of code plus a () code called a function, and then, in the C language to define the function of the standard format is: return value type declarator + a space + function name + (), and then in parentheses to fill in the parameters of the function, then this int It is obvious that the so-called "return value type Declarator", but "return value type Declarator" is not the only one, why do you want int ? Because, in the last line of theprogram: Return (return) is 0,0 is an integer, in the C language data type Integer belongs to shaping, and int is the shaping type declarator, so is an int Instead of the other (about the data type, we'll talk about it in the next section).

In order to explain a little later, I had to speak in a rude way. :)

The following is a C-language rule (Note: Rules are rules, no why!) Ok? The C language stipulates that each C language program must have at least one function, whereas in the case of only one function, the function can only be called main (main function).

(PS: Just so willful ....) )

Then, the next rule: the C language stipulates that a function must be in the following format:

return value type declarator function name (formal parameter)

function body

The only function in our first program, the main function, has no arguments, so the parentheses are empty. (I am capricious in the banner of C language, do not obey?) Come and bite me .... aha haha haha (no words ...) ))

Next rule: C language rules C program execution, no matter how many functions are executed from the main function! The function body inside the main function can call all the functions in the program!

o A k, such a simple and rude, haha.

Now, the only thing we don't understand is the 5th line:printf("Hello world!"); ..... This line of the main function calls the printf () function defined in the Stdio.h header file that is inserted into the program with the include directive, then the function uses the format:

printf (what to output);

The content to be output must be enclosed in double quotation marks (""). Because, your foundation is too poor, can not explain to you, you think this is a rule.

Finally for beginners good understanding, I created a rule, for the early learning is very helpful, but to the late, this rule is not necessarily. Rule: Be sure to add a semicolon (;) after executing a statement in the function body of the main function.

OK, this section is here, welcome the problem of children's shoes plus I qq:2937605316, I will answer.

Next: C language data types and variables, learn the next lesson we can know why the parameters of the printf function "to output the content" to add double quotation marks. (Praise, Seek)






This article is from the "Lucifer ﹟sec" blog, please make sure to keep this source http://2937605316.blog.51cto.com/10484262/1670957

C Language Introductory Learning tutorial -2-hello world!

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.