C Primer Plus Study notes (i)-C language overview

Source: Internet
Author: User
Tags function prototype

Start with a simple C language program

#include <stdio.h>/* It is a simple C language program *///   comment int main (void) {int num;num = 1;printf ("This is a C program!\n");p rintf ("Number is%d\n", num); return 0;}

#include <stdio.h> Stdio.h is included in the current program, STDIO.H is the standard part of the C compiler package for keyboard input and screen output

Main () is a function name, and the main () function is the primary entry for the C program, and int indicates that the main () function returns an integer that returns to the operating system with the parameter void indicating main () without any arguments

int and void are part of the standard ansic definition of main (), and if you use a compiler prior to ansic, omit void

' {', Start for function body

int num;, to declare a variable num of type int (integer), all variables must be declared before they can be used

num = 1; Assigns a value of 1 to the variable num for an assignment expression statement

printf (' This is a C program! ');, call the printf () function to print this is a C program! the phrase, "' This is a C program! '" is the actual argument of the printf () function

printf (' number is%d ', num); it is also called the printf () function to print,%d as a placeholder for the position indicating the output num value

return 0; When the main () function finishes executing, it returns a value 0,main () function ends with a return statement, and if there is no return statement in the main () function, 0 is returned by default when the function finishes executing

"}", End for function body

As you can see, each statement in the function body ends with a semicolon, and if there is no semicolon, the compiler will error, and if the compiler complains that a line is missing a semicolon, check whether the previous line has a semicolon ending

Program Run Result:

Declaring multiple variables
int A, B, c;//can also write int a;int b;int C;
Name of the variable

can be named with lowercase letters, capitals, numbers, and underscores (_), and the 1th character of a variable name must be a character or an underscore, not a number.

The naming in the C language is case-sensitive, which is to treat the uppercase and lowercase of a letter as two different characters.

Operating systems and C libraries often use an identifier that starts with one or two underscore characters, so use this name whenever possible to avoid declaring variables. Standard labels start with one or two underscore characters, such as library identifiers, which are reserved and may be heavy when named, although there is no syntax error, but can cause name collisions

Multiple functions
#include <stdio.h>void Test (void);  Function prototype (function declaration) int main (void) {printf ("before run the Test function\n"); Test ();   Function call printf ("After run the Test function\n"); return 0;} void Test (void)  //function definition {printf ("This is the Test function\n");}

A function prototype is also called a function declaration, which tells the compiler to use the function in the program, the function prototype also indicates the properties of the function, the 1th void means that the test () function has no return value (usually the called function returns a return value to the main function), and the 2nd void indicates that the test () function has no arguments

A function call is a call to the test () function in the main () function

The final function definition is the source code that defines the test () function itself

Program Run Result:

Summary:

The C program consists of one or more C functions.

Each C program must contain a main () function, and the main () function is the primary entry for the C program, which is the first function called by the C program.

A simple function consists of a function head and a pair of curly braces in the back, which are the body of a function composed of declarations and statements.

In the C language, most statements end with a semicolon.

A declaration statement specifies a variable name for a variable and identifies the data type stored in the variable, which is an identifier.

An assignment expression statement assigns a value to a variable, which assigns the value to the storage space.

The function expression statement is used to invoke the specified named function, and when the calling function finishes executing, the program returns to the statement following the function call to continue execution.

The printf () function is used to output content.

Keywords are the words of the C language.

Review questions:

What is the basic module of 1.C language?

Answer: function

6. What are the C language keywords in main, int, function, char, =?

A: int and char are the keywords of the C language, and main is a function name, function is the meaning of functions, = is an operator

C Primer Plus Study notes (i)-C language overview

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.