
-------------------------------------------------
Comments
Comments Begin with //, indicating that these two lines are Idea. You insert Idea to document programs and improve program readability. Comments do not cause the computer to perform any action when the program is run. Comments are ignored by the C compiler and do not cause any machine-language object code to be generated. The preceding comment simply describes the figure number, file name and purpose of the program. Comments also help other people read and understand your program. You can also use /*…*/ multi-line Idea in which everything from /* on the first line to */ at the end of the last line is a comment. We prefer // Idea because they’re shorter and they eliminate common programming errors that occur with /*…*/ Idea, especially when the closing */ is omitted.
#include Preprocessor Directive
#include is a directive to the C preprocessor. Lines begiing with # are processed by the preprocessor before compilation.
< stdio.h > = C file input/output
The C programming language provides many standard library functions for file input and output. These functions make up the bulk of the C standard library header . The functionality descends from a "portable I/O package" written by Mike Lesk at Bell Labs in the early 1970s, and officially became part of the UNIX operating system in Version 7.
The I/O functionality of C is fairly low-level by modern standards; C abstracts all file operations into operations on streams of bytes, which may be "input streams" or "output streams". Unlike some earlier programming languages, C has no direct support for random-access data files; to read from a record in the middle of a file, the programmer must create a stream, seek to the middle of the file, and then read bytes in sequence from the stream.
The stream model of file I/O was popularized by UNIX, which was developed concurrently with the C programming language itself. The vast majority of modern operating systems have inherited streams from UNIX, and many languages in the C programming language family have inherited C's file I/O interface with few if any changes.
Blank Lines and White Space
You use blank lines, space characters and tab characters (i.e., “tabs”) to make programs easier to read. Together, these characters are known as white space. White-space characters are normally ignored by the compiler.
The main Function
The main Function is a part of every C program. The parentheses after main indicate that main is a program building block called a function. C programs contain one or more functions, one of which must be main. Every program in C begins executing at the function main. Functions can return information. The keyword int to the left of main indicates that main “returns” an integer (whole-number) value. For now, simply include the keyword int to the left of main in each of your programs. Functions also can receive information when they’re called upon to execute. The void in parentheses here means that main does not receive any information.
left brace { , right brace }
A left brace, {, begins the body of every function. A corresponding right brace ends each function. This pair of braces and the portion of the program between the braces is called a block. The block is an important program unit in C.The right brace, }, indicates that the end of main has been reached.
An Output Statement
Instructs the computer to perform an action, namely to print on the screen the string of characters marked by the quotation marks. A string is sometimes called a character string, a message or a literal. The entire line, including the printf function (the “f” stands for “formatted”), its argument within the parentheses and the semicolon (;), is called a statement.
Every statement must end with a semicolon (also known as the statement terminator). When the preceding printf statement is executed. The characters normally print exactly as they appear between the double quotes in the printf statement.
Escape Sequences
Notice that the characters n were not printed on the screen. The backslash () is called an escape character. It indicates that printf is supposed to do something out of the ordinary. When encountering a backslash in a string, the compiler looks ahead at the next character and combines it with the backslash to form an escape sequence. The escape sequence n means newline. When a newline appears in the string output by a printf, the newline causes the cursor to position to the begiing of the next line on the screen.
Because the backslash has special meaning in a string, i.e., the compiler recognizes it as an escape character, we use a double backslash (\) to place a single backslash in a string. Printing a double quote also presents a problem because double quotes mark the boundaries
of a string—such quotes are not printed. By using the escape sequence " in a string to be output by printf, we indicate that printf should display a double quote.
برچسب:
نویسنده: حسین رستمی