Professional Documents
Culture Documents
1
1.1 History of C
1960 ALGOL International Group
main(
main( )) function
{{
comment
/*…………printing
/*…………printing begin
begin …………*/
…………*/ lines
printf(“I
printf(“I see
see ,, II rember”);
rember”);
/*………….pinting executive
/*………….pinting end…………….*/
end…………….*/
statement
}}
The Main Function
The main is a part of every C program. C permits
different forms of main statement. Following forms are
allowed.
main()
int main()
void main()
main(void)
void main(void)
int main(void)
The empty pair of parentheses indicates that the
function has no arguments. This may be explicitly
indicated by using the keyword void inside the word
main. The keyword void means that the function does
not return any information to the operating system and
int means that the function returns a integer value to
the operating system. When int is specified, the last
statement in the program must be “return 0”.For the
sake of simplicity, we use the first form in our
programs.
Format of Simple C Programs
main(
main( )) Function name
{{ Start of program
…………
…………
…………
………… Program statements
…………
…………
}} End of program
1.4 Sample Program 2:
Adding Two Numbers
Link
Link Section
Section aa
Definition
Definition Section
Section aa
Global
Global Declaration
Declaration Section
Section aa
main()
main() Function
Function Section
Section
{{ Declaration part
Executable part
}} aa
Subprogram
Subprogram section
Function 1
section
Function 2
- (User-defined functions)
-
Function n
1.9 Programming Style
We must develop the habit of writing
programs in lowercase letters.
Braces group program statements together
and mark the beginning and the end of
functions.
The generous use of comments inside a
program cannot be overemphasized.
1.10 Executing A ‘C’ Program
Executing a program written in C involves a
series of steps:
1. Creating the program
2. Compiling the program
3. Linking the program with functions that are
needed from the C library
4. Executing the program
Start
Edit
.C
Source Program
Compile
Y Errors? .OBJ
Object Program
N
System Library
and Other Link
Object Program
.EXE
Y Errors? Executive
Program
N
Execute
N
Result Right ?
Y Process
End
Just
Just Remember
Remember