Let us begin with a quick introduction in C.
The only way to learn a new programming language is by writing programs in it.
Now, for some explanations about the program itself. A C program, whatever its size, consists of functions and variables. A function contains statements that specify the computing operations to be done, and variables store values used during the computation.C functions are like the subroutines and functions in Fortran or the procedures and functions of Pascal. Our example is a function named "main". Normally you are at liberty to give functions whatever names you like, but "main" is special---your program begins executing at the beginning of "main". This means that every program must have a "main" somewhere. And "main" will usually call other functions to help perform its job, some that you wrote, and other from libraries that are provided for you. The first line of the program, "#include <stdio.h>" tells the compiler to include information about the standard input/output library; the line appears at beginning of many C source files. The standard library is described in Chapter & and Appendix B.
One method of communicating data between functions is for the calling function to provide a list of values, called arguments, to the function it calls. The parentheses after the function name surround the argument list. In this example, "main" is defined to be a function that expects no arguments, which is indicated by the emptylist ().
#include <stdio.h>
main ()
{
printf("hello, world\n");
}
The statements of a function are enclosed in braces {}. The function "main" contains only one statement, "printf("hello, world\n");".
The function 'printf" is a library function that prints output, in this case the string of characters between the quotes. A sequence of charaaters in double quotes, like "hello world\n", is called a character string or string constant.
转义字符:在C语言中,用反斜线字符“\”作为转义字符,来表示那些不可打印的ASCII控制符。
\a: alter(bell) character
\b: backspace
\f: formfeed
\n: newline
\r: carriage return
\t: horizontal tab
\v: vertical tab
\\: backslash
\?: question mark
\': single quote
\": double quote
\ooo octal number-\ddd 1~3 位八进制数所代表的字符
\xhh: hexadecimal number--\xhh 1~2 位十六进制数所代表的字符
We recommended writing only one statement per line, and using blanks around oerators to clarify grouping.
How "printf" works?
Its first argument is a string of characters to be printed, with each % indicating where one of the other(second, third, ...) arguments is to be substituted, and in what form it is to be printed. For instance, %d specifies an integer argument. By the way, "printf" is not a part of the C language; there is no input or output defined in C itself.
Among others, in printf, %% for itself
网友评论