You are on page 1of 4

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. #include <stdio.h> tells the compiler to include information about the standard input/output library; Each source file that refers to an input/output library function must contain the line #include <stdio.h> before the first reference. When the name is bracketed by < and > a search is made for the header in a standard set of places (for example, on UNIX systems, typically in the directory /usr/include). The sequence \n in the string is C notation for the newline character, which when printed advances the output to the left margin on the next line. printf never supplies a newline character automatically, so several calls may be used to build up an output line in stages. Certain characters can be represented in character and string constants by escape sequences like \n (newline); these sequences look like two characters, but represent only one.\t for tab, \b for backspace, \" for the double quote and \\ for the backslash itself. The type int means that the variables listed are integers; by contrast with float, which means floating point, i.e., numbers that may have a fractional part. char -character - a single byte; e.g.celsius = 5 * (fahr-32) / 9; The reason for multiplying by 5 and dividing by 9 instead of just multiplying by 5/9 is that in C, as in many other languages, integer division truncates: any fractional part is discarded. Since 5 and 9

third.0 is not truncated because it is the ratio of two floating-point values.0f says that a floating-point number is to be printed at least three characters wide. since it handles only positive powers of small integers a return value of zero implies normal termination . since it is more compact than while and it keeps the loop control statements together in one place.) arguments is to be substituted. The replacement text can be any sequence of characters. %6. 5/9 would be truncated to zero and so all the Celsius temperatures would be reported as zero.. A decimal point in a constant indicates that it is floating point.. printf is just a useful function from the standard library of functions that are normally accessible to C programs.are integers. however. and in what form it is to be printed. each % indicates where one of the other (second. Pow(m.1f describes another number that is to be printed at least six characters wide. with 1 digit after the decimal point. with no decimal point and no fraction digits.0/9. it is not limited to numbers. The printf conversion specification %3. The name has the same form as a variable name: a sequence of letters and digits that begins with a letter. so 5. . printf is not part of the C language.n) This function is not a practical exponentiation routine. The for is usually appropriate for loops in which the initialization and increment are single statements and logically related. #define name replacement list any occurrence of name (not in quotes and not part of another name) will be replaced by the corresponding replacement text. there is no input or output defined in C itself.

can be written in the compressed form i += 2. the do-while. while and for loops test the termination condition at the top. Relational operators have lower precedence than arithmetic operators. . The two most frequently used features are #include. and p is said to ``point to'' c. If the name is followed by an equals sign and an expression. x % y produces the remainder when x is divided by y.. the expression serves as an initializer. to include the contents of a file during compilation. to replace a token by an arbitrary sequence of characters.A variable may also be initialized in its declaration. An expression such as x = 0 or i++ or printf(.just below them in precedence are the equality operators ++n increments n before its value is used. assigns the address of c to the variable p. By contrast. the third loop in C. the body is always executed at least once. Braces { and } are used to group declarations and statements together into a compound statement. and #define. or block.The operator += is called an assignment operator. so that they are syntactically equivalent to a single statement. cannot be applied to a float or double. while n++ increments n after its value has been used. p = &c. An expression such as i = i + 2 in which the variable on the left side is repeated immediately on the right.) becomes a statement when it is followed by a semicolon.. tests at the bottom after making each pass through the loop body.

These are identical to scanf and printf. the format string is the second argument. such as the location of a buffer. interprets them according to the specification in format. mode). Before it can be read or written. the current character position in the buffer.scanf reads characters from the standard input. because the definitions obtained from <stdio. also a character string. the other arguments. The format argument is described below. The second argument is the mode. . The first argument of fopen is a character string containing the name of the file. Users don't need to know the details. and stores the results through the remaining arguments.h> include a structure declaration called FILE. indicate where the corresponding converted input should be stored. file pointer. which indicates how one intends to use the file. and whether errors or end of file have occurred. except that the first argument is a file pointer that specifies the file to be read or written. whether the file is being read or written. The call to fopen in a program is fp = fopen(name. points to a structure that contains information about the file. each of which must be a pointer. a file has to be opened by the library function fopen. the functions fscanf and fprintf may be used.