Download presentation
Presentation is loading. Please wait.
1
C Programming Hardik H. Maheta
2
Programming in ANSI C by E Balagurusamy Reference Books
Text Book Programming in ANSI C by E Balagurusamy Reference Books The C Programming Language by Kerninghan & Ritchie Let us C by Yashwant Kanitkar Hardik H. Maheta
3
Program Programming Language What do you mean by Language?
A Set of instructions which when carried out by processor for some specific input, generates specific output. Programming Language A specific manner of writing a program with some predefined rules, symbols & their use as a part of language. i.e. Pascal, C, C++, VC++, JAVA, VB. Hardik H. Maheta
4
Standardization Committee
History of C 1960 ALGOL International Group 1967 BCPL Martin Richards 1970 B Ken Thompson 1972 Traditional C Dennis Ritchie 1978 K&R C Kernighan & Ritchie 1989 ANSI C ANSI Committee 1990 ANSI/ISO C ISO Committee 1999 C99 Standardization Committee Hardik H. Maheta
5
Features of C Structured High-Level Machine-Independent & Portable
Powerful Efficient Compact Close to both man & machine Fast Hardik H. Maheta
6
Types of Languages Lower-Level Languages (Machine Language)
-Languages near to the machines -binary language like Assembly Languages Higher-Level Languages -Languages near to programmers -C,C++,JAVA Hardik H. Maheta
7
Hardik H. Maheta
8
Basic Structure of C Programs
Documentation Section (Comment Lines) Link Section (Link Functions from the System Library) Definition Section (Defines all Symbolic Constants) Global Declaration Section (Defining Variables used Globally + Declaration of User Defined Functions) main ( ) Function Section { Declaration Part Executable Part } Subprogram Section Function 1 Function 2 and so on … Hardik H. Maheta
9
Documentation Section
It is set of comment lines (Name of program, Author details, Aim of program) What is Comment line?? To guide a programmer. To write a note for function, operation, logic in between a program. It is not necessary but used to Increase the readability of program. Non-executable statement. i.e /* This is Comment*/ Hardik H. Maheta
10
Link Section It provides instructions to the compiler to link
function from the system library. # include Directive To access the functions which are stored in the library, it is necessary to tell the compiler , about the file to be accessed. Syntax:- #include<stdio.h> stdio.h is header file. Hardik H. Maheta
11
Definition Section It defines all symbolic constants.
#define instruction defines value to a symbolic constant. #define It is a preprocessor compiler directive, not a statement. Therefore it should not end with a semicolon. Generally written in uppercase. Syntax #define PI Hardik H. Maheta
12
Global Declaration Section
Some variables that are used in more than on function, such variables (global variables) declared in the global declaration section. It also declares all the user-defined function. Hardik H. Maheta
13
main() function section
Every ‘C’ program must have one main() function section. It contains two parts Declaration part It declares all variables used in the executable part. Executable part: It has at least one statement. All the statement in declaration part and Executable part ends with semicolon(;). main() function is called by operating system and it returns information to operating system Hardik H. Maheta
14
Different forms of main() function
Function has no arguments and return no information to operating system. int main() Function has no arguments and return integer information to operating system. In this last statement should be return 0; void main() Function has no arguments and Explicitly define return no information to operating system. main(void) Explicitly define Function has no arguments and return no information to operating system. void main(void) Explicitly define Function has no arguments and Explicitly define return no information to operating system. int main(void) Explicitly define Function has no arguments and return integer information to operating system. In this last statement should be return 0; Hardik H. Maheta
15
Sample C program /* Sample Program to print Hello World */ /* Documentation section */ #include<stdio.h> /* link section*/ void main() /* execution of program*/ { printf(“Hello World”); /*executable statement*/ } Hardik H. Maheta
16
Sample C program /* Sample Program to Add two numbers */ /* Documentation section */ #include<stdio.h> /* link section*/ void main() /* execution of program*/ { int no1=10, no2=5, sum; /*Declaration Part*/ sum = no1+no2; Printf(“Sum = %d”, sum); /*Executable Part*/ } Hardik H. Maheta
17
Executing a ‘C’ Program
Creating the Program Compiling the Program Linking the Program with functions that are needed from the C Library Executing the Program Hardik H. Maheta
18
Compiler Why compiler is require ?
As machine (a processor) can operate only on binary code instruction If we use higher level language then for execution of the program we must convert it to lower level / machine level Code. This task of converting human readable language to machine readable language is done by the compiler. A program that translates source code into object code is called compiler. Hardik H. Maheta
19
Interpreter C Compiler
It analyses and executes each line of the source code, without looking at the entire program, unlike the compiler. Advantage: It can execute program immediately Good for small programs C Compiler - checks for syntax errors if no error than coverts ‘C source code into object code form which is nearer to machine level language. Hardik H. Maheta
20
Linker A linker combines object to form an executable program.
As many programming languages allow us to write different pieces of code, called modules which simplifies the task as a large program can be broken down into small, more manageable pieces. It is Linker which puts all these modules together. Hardik H. Maheta
21
Hardik H. Maheta
22
Compiling & Executing C Program
If you are using Linux, you could simply use the command gcc –o objfilename cfilename to compile your c program. And ./objfilename to run your compiled C program. If you are using Turbo C Compiler, you could directly select the compile(Alt+f9) to compile program and run(ctrl+f9) option from the menu-bar. Hardik H. Maheta
23
Compile Source program Link with System Library
System Ready Program Code Enter Program Edit Source Program C Compiler Compile Source program Yes Syntax Error No System Library Link with System Library Logic Error Input Data Execute Object Code Logic & Data Error Data Error No Error Output Hardik H. Maheta
24
Block Diagram Represents only -> what should be the input?
-> what will be the output? One need not to worry about how the result generated or what will be the logic for the program? Block Diagram for making addition of two numbers Input Output PROGRAM No1. & No2. No1 + No2
25
Algorithm Specifies steps of doing the things Irrespective of any programming language Example: Addition of two numbers Step 1: [Read two numbers] Read(no1) Read(no2) Step 2:[add two numbers into sum] summation = no1 + no2 Step 3:[Display the result] write (summation) Hardik H. Maheta
26
Flowchart Represents the flow of program Symbols Start-Begin/End
Input/output Rectangle Process box/operation box Decision Box Connector Hardik H. Maheta
27
Write Summation on monitor
Flowchart-example Example: To add two numbers and display the result. Start Read No1 and No2 from user SUMMATION = NO1 + NO2 Write Summation on monitor End Hardik H. Maheta
28
Thank You Hardik H. Maheta
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.