1 / 16

Introduction to Computer (C Programming)

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.

carlota
Download Presentation

Introduction to Computer (C Programming)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Computer (C Programming) Chapter 1 Overview of C

  2. 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

  3. 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.

  4. 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.

  5. 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

  6. 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

  7. 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

  8. 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

  9. 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

  10. /*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

  11. 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.

  12. 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

  13. 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.

  14. 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

  15. 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

  16. 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.

More Related