210 likes | 600 Views
Introduction to Computer (C Programming). Chapter 1 Overview of C . Roadmap. 1.1 History of C 1.2 Importance of C 1.3 Simple Program 1 1.4 Simple Program 2 1.5 Basic Structure of C Programs 1.6 Programming Style 1.7 Executing a ‘ C ’ Program. 1.1 History of C.
E N D
Introduction to Computer (C Programming) Chapter 1 Overview of C
Roadmap • 1.1 History of C • 1.2 Importance of C • 1.3 Simple Program 1 • 1.4 Simple Program 2 • 1.5 Basic Structure of C Programs • 1.6 Programming Style • 1.7 Executing a ‘C’ Program
1.1 History of C • C language was evolved from ALGOL, BCPL and B by Dennis Ritchie at Bell Laboratories in 1972. • C language is a structured, high-level, machine independent language.
1960 1972 ALGOL Traditional C International Group Dennis Ritchie 1967 BCPL Martin Richards 1970 B Ken Thompson 1978 K&R C Kernighan and Ritchie 1989 ANSI C ANSI Committee 1990 ISO Committee ANSI/ISO C 1.1 History of C Cont.
1.2 Importance of C • The increasing popularity of C is probably due to its many desirable qualities. • Programs written in C are efficient and fast • There are only 32 keywords and its strength lies in its built-in functions • C is highly portable • C language is well suited for structured programming • C can extend itself
1.3 Sample Program 1: Printing a Message #include <stdio.h> main( ) { /*…………printing begin …………*/ printf(“I see , I rember”); /*………….pinting end…………….*/ } Function body Function Comment lines executive statement
1.3 Sample Program 1: Printing a Message Cont. • The main is a part of every C program. Following forms are allowed. • main() • int main() • void main() • main(void) • void main(void) • int main(void) ()/(void): the function has no arguments int : return an integer value void : return no value
Format of Simple C Programs 1.3 Sample Program 1: Printing a Message Cont. Function name main( ) { ………… ………… ………… } Start of program Program statements End of program
1.4 Sample Program 2: Adding Two Numbers • Consider another program , which performs addition on two numbers and displays the result . The complete program is shown
/*Program ADDITION line-1 */ #include <stdio.h> /* line-2 */ main() /* line-3 */ { /* line-4 */ int number; /* line-5 */ float amount; /* line-6 */ /* line-7 */ number = 100; /* line-8 */ /* line-9 */ amout = 30.75 + 75.35; /*line-10 */ printf(“%d\n ”,number); /*line-11 */ printf(“%5.2f”,amount); /*line-12 */ } 1.4 Sample Program 2: Adding Two Numbers • Consider another program , which performs addition on two numbers and displays the result . The complete program is shown
1.5 Basic Structure of C Programs • A C program can be viewed as a group of building blocks called functions. • A function is a subroutine that may include one or more statementsdesigned to perform a specific task. • To write a C program, we first create functions and then put them together.
Documentation Section a Link Section a Definition Section a Global Declaration Section a main() Function Section { } a Subprogram section Declaration part Executable part Function 1 Function 2 (User-defined functions) - - Function n
1.6 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.7 Executing A ‘C’ Program • Executing a program written in C involves a series of steps: • Creating the program • Compiling the program • Linking the program with functions that are needed from the C library • Executing the program
start Edit .C Source Program Compile Y Errors? .OBJ Object Program N System Library and Other Object Program Link .EXE Executive Program Y Errors? N Execute N Result Right? Y end
Just Remember • Every C Program requires a main() function. • The place main is where the program execution begins. • We must make sure to include header files using #include directive when the program refers to special names and functions that it does not define.