C Programming Hardik H. Maheta.

Slides:



Advertisements
Similar presentations
Introduction to C Programming CE Lecture 1 Introduction to C.
Advertisements

CSE1301 Computer Programming Lecture 4: C Primitives I.
Three types of computer languages
Program Flow Charting How to tackle the beginning stage a program design.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
Guide To UNIX Using Linux Third Edition
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
C programming Language and Data Structure For DIT Students.
Introduction to C. A Brief History Created by Dennis Ritchie at AT&T Labs in 1972 Originally created to design and support the Unix operating system.
CHAPTER 1: INTORDUCTION TO C LANGUAGE
Computer Science 210 Computer Organization Introduction to C.
Welcome In The World Of ‘C’.  TEXT BOOK: Programming in ANCI ‘C By: E Balagurusamy. TMH  Reference Books: 1) The ‘C Programming Language By: Kernighan.
“C” Programming Language What is language ? Language is medium of communication. If two persons want to communicate with each other, they have to use.
Introduction to C Programming. A Brief History u Created by Dennis Ritchie at AT&T Labs in 1972 u Originally created to design and support the Unix operating.
CSC141 Introduction to Computer Programming
Programming With C.
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
Sharda University P. K. Mishra (Asst.Prof) Department of Computer Science & Technology Subject Name: Programming Using C Sub Code: CSE-106 Programming.
INTRODUCTION TO COMPUTING CHAPTER NO. 04. Programming Languages Program Algorithms and Pseudo Code Properties and Advantages of Algorithms Flowchart (Symbols.
Chapter 1 Introduction Chapter 1 Introduction 1 st Semester 2015 CSC 1101 Computer Programming-1.
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
CHAPTER 1 INTRODUCTION 1 st Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
CHAPTER 1 INTRODUCTION 2 nd Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
DOCUMENTATION SECTION GLOBAL DECLARATION SECTION
Introduction to C Programming Language. History of C  C was evolved by Dennis Ritchie at AT&T Bell Laboratories in early of 1970s  Successor of: ALGOL.
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
Principles of Programming CSEB134 : BS/ CHAPTER Fundamentals of the C Programming Language.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
Intro. to Computer Programming Eng. Nehal A. Mohamed Spring Semester-2016.
INTRODUCTION TO PROGRAMING System Development Mansoura October 2015.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 1.
Introduction to C Topics Compilation Using the gcc Compiler
Chapter 1 Introduction 2nd Semester H
PROGRAMMING WITH C ++.
UMBC CMSC 104 – Section 01, Fall 2016
Computer Science 210 Computer Organization
CSC201: Computer Programming
Unit 3: ALGORITHMS AND FLOWCHARTS
CSCI-235 Micro-Computer Applications
Microprocessor and Assembly Language
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
History of ‘C’ Root of the morden language is ALGOL It’s first
Overview of C.
Introduction to C Topics Compilation Using the gcc Compiler
Getting Started with C.
C language IT-1 (Batch-A) Name: EnNo: Arshad Muthalif
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to C Programming Language
' C ' PROGRAMMING SRM-MCA.
Choice of Programming Language
Welcome In The World Of ‘C’.  TEXT BOOK: Programming in ANSI ‘C By: E Balagurusamy. TMH  Reference Books: 1) The ‘C Programming Language By: Kernighan.
Computer Science 210 Computer Organization
The C Programming Language
Introduction to C Programming
Introduction to C Topics Compilation Using the gcc Compiler
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
2008/09/29: Lecture 7 CMSC 104, Section 0101 John Y. Park
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
A programming language
C programming Language
Introduction to Computer Programming
Introduction to C Topics Compilation Using the gcc Compiler
C Programming Language
Introduction to C Topics Compilation Using the gcc Compiler
Computer Science Department
Presentation transcript:

C Programming Hardik H. Maheta

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

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

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

Features of C Structured High-Level Machine-Independent & Portable Powerful Efficient Compact Close to both man & machine Fast Hardik H. Maheta

Types of Languages Lower-Level Languages (Machine Language) -Languages near to the machines -binary language like 010101 Assembly Languages Higher-Level Languages -Languages near to programmers -C,C++,JAVA Hardik H. Maheta

Hardik H. Maheta

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

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

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

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 3.1416 Hardik H. Maheta

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

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

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

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

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

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

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

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

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

Hardik H. Maheta

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

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

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

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

Flowchart Represents the flow of program Symbols Start-Begin/End Input/output Rectangle Process box/operation box Decision Box Connector Hardik H. Maheta

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

Thank You Hardik H. Maheta