"C Programming Language: (2nd ed.) Modern methods of" Basic Concepts Chapter 2 C language

Chapter 2 Basic Concepts C language

Someone else may be constant variables.

This chapter describes some of the basic concepts of the C language, including pre-processing commands, functions, variables and statements. Even the simplest is to write a C program that will use these basic concepts. Subsequent chapters of these concepts will be described in more detail.

First, 2.1 gives a simple C program and describes how to compile and link the program. Then, 2.2 discusses how to make the program universal. Section 2.3 describes how to add a descriptive interpretation, known as the comments. Section 2.4 describes the variables, variables are used to store execution data may occur during the change. Section 2.5 described using the scanf read data into the variable of the method. As above, the constant data does not change during execution of the program described in section 2.6, the user can be named. Finally, Section 2.7 naming explain the C language (identifier) ​​Rules, Section 2.8 gives the layout specification C programs.

2.1 Write a simple C program

Compared with the procedures written in other languages, C program requires less "formal thing." A complete C program may be only a few lines.

Program: Show pun

Kernighan and Ritchie written in C language classic book The C Programming Language book, the first program is extremely short. It is only the output of a hello, world news. Most of the C language books and different, I do not intend to use the first example of a C program, as this program, and more willing to respect the traditions of another C language: Show pun. Here is a pun:

To C, or not to C: that is the question.

The following program will pun.c named above message is displayed on each run.

/**
 * pun.c
 */

#include <stdio.h>

int main() {
    printf("To C, or not to C: that is the question.\n");
    return 0;
}

Section 2.2 of this program will have some of the format detailed explanation, here only do a brief introduction. The first line of the program

#include <stdio.h>

It is essential that it "contains" relevant information C language standard I / O library. The executable code in the main function, this function represents the "master" program. The first line of code in the main function is used to display the information desired. printf function from the standard input / output library may be generated perfectly formatted output. Code \ n tells printf function after executing the message display line feed operation to be performed. The second line of code,

return 0;

It showed that the program terminates returns the value 0 to the operating system.

Guess you like

Origin www.cnblogs.com/shenhuanjie/p/11416592.html