C programming Language

Slides:



Advertisements
Similar presentations
C Language.
Advertisements

Chapter 3: Beginning Problem Solving Concepts for the Computer Programming Computer Programming Skills /1436 Department of Computer Science.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Introduction to Computing Lecture 01: Introduction to C Introduction to Computing Lecture 01: Introduction to C Assist.Prof.Dr. Nükhet ÖZBEK Ege University.
Structure of a C program
Three types of computer languages
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
1 ICS103 Programming in C Lecture 2: Introduction to C (1)
Introduction to C Programming
C programming Language and Data Structure For DIT Students.
Introduction to C language
CHAPTER 1: INTORDUCTION TO C LANGUAGE
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
“C” Programming Language What is language ? Language is medium of communication. If two persons want to communicate with each other, they have to use.
Basics of “C” Programming
C Tokens Identifiers Keywords Constants Operators Special symbols.
C-Language Keywords(C99)
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Programming With C.
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
Lecture #5 Introduction to C++
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Dennis Ritchie 1972 AT & T Bell laboratories (American Telephone and Telegraph) USA 1www.gowreeswar.com.
C programming language was developed in the seventies by a group of at the Bell Telephone lab. The C language was the outline of two earlier languages.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Constants, Variables and Data types in C The C character Set A character denotes any alphabet, digit or special symbol used to represent information.
Agenda Computer Languages How to Write a Simple C Program
An overview of C Language. Overview of C C language is a general purpose and structured programming language developed by 'Dennis Ritchie' at AT &T's.
MAHENDRAN. Session Objectives Session Objectives  Discuss the Origin of C  Features of C  Characteristics of C  Current Uses of C  “C” Programming.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Introduction to C Programming I Subject: T0016 – ALGORITHM AND PROGRAMMING Year: 2013.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 1.
CSE-102: PROGRAMMING FUNDAMENTALS LECTURE 3: BASICS OF C Course Instructor: Syed Monowar Hossain 1.
Numbers in ‘C’ Two general categories: Integers Floats
C++ Lesson 1.
Introduction to ‘c’ language
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
CSC201: Computer Programming
Completing the Problem-Solving Process
Introduction to C Language
C Programming Hardik H. Maheta.
C Language VIVA Questions with Answers
Getting Started with C.
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
Introduction to C Programming Language
' C ' PROGRAMMING SRM-MCA.
Choice of Programming Language
INTRODUCTION c is a general purpose language which is very closely associated with UNIX for which it was developed in Bell Laboratories. Most of the programs.
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 Programming LAB 1 Tejalal Choudhary Asst. Prof, CSE Dept.
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
פרטים נוספים בסילבוס של הקורס
Basics of ‘C’.
פרטים נוספים בסילבוס של הקורס
Introduction to C Programming
Govt. Polytechnic,Dhangar
Introduction C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell.
Govt. Polytechnic,Dhangar
Programming Fundamentals Lecture #3 Overview of Computer Programming
WEEK-2.
The C Language: Intro.
C – Programming Language
C Language B. DHIVYA 17PCA140 II MCA.
Basic Programming Lab C.
Presentation transcript:

C programming Language For SSUET- Electronic Students

Introduction to C Programming

Books “Turbo C Programming for PC”, Robert Lafore, SAMS Teach Yourself C : Herbert Schildt

Language? Source of Communication between two persons. OR Example: Human –To- Human OR Source of Communication between User and Computer is called programming language. Example: Human –To- Machine

Program Set of instructions which perform any specific task is called program.

What is programming? Series of instructions to a computer to achieve a task Instructions must be written in a way the computer can understand Programming languages are used to write programs Once the code (language) of a program has been written, it must be executed (run, started). Some programming languages (like C, C++ or Java) require the code to be compiled (translated to binary) before it can be started.

History of C language Year Language Developer 1960 ALGOL (Algorithmic Language) Internal Committee 1967 BCPL (Basic Combined Programming Language) Martin Richards 1970 B Ken Thompson 1972 C Dennis Ritchie

What is C? C A language written by Dennis Ritchie in 1972 at AT&T Bell Labs USA. This was to be the language that UNIX was written in to become the first "portable" language. In recent years C has been used as a general-purpose language because of its popularity with programmers. AT&T-American Telephone and Telegraph UNIX-Uniplexed Information and Computing System or Service

Why C Still Useful? C provides: C is used: Efficiency, high performance and high quality Provide functionality through rich set of function libraries Gateway for other professional languages like C  C++  Java C is used: System software, Compilers, Editors Graphics and Geometry Databases, operating systems, device drivers Also used in application programs

Software Development Method Requirement Specification Problem Definition Analysis Refine, Generalize the problem definition Design Develop Algorithm: (A formula or set of steps for solving a particular problem) Implementation Write Code Verification and Testing Test and Debug the code

How do you write a program? Decide what steps are needed to complete the task Write the steps (Algorithm) in pseudo code (written in English) or as a flowchart (graphic symbols) Translate into the programming language Try out the program and “debug”.

Getting started with C Steps in learning English language Steps in learning C Alphabets Sentences Paragraph Words Alphabets Digits Special-symbols Constants Variables Keywords Instruction Program Programming with C 12

Sample Pseudo code Task: add two numbers Pseudo code (Algorithm) : Start Get two numbers Add them (a + b) Print the answer End

What does a flowchart look like? Pseudo code (Algorithm) : Start Get two numbers Add them (A + B) Print the answer End Start Get 2 numbers A+B Print answer End

Flow Chart symbols START/END INPUT/OUTPUT PROCESS DECISION

Integrated Development Environments An integrated development environment (IDE) is a software package that makes it possible to edit, compile, link, execute, and debug a program without leaving the environment. 16

Header Files The files that are specified in the include section is called as header file These are precompiled files that has some functions defined in them We can call those functions in our program by supplying parameters Header file is given an extension .h C Source file is given an extension .c

Main Function This is the entry point of a program When a file is executed, the start point is the main function From main function the flow goes as per the programmers choice. There may or may not be other functions written by user in a program Main function is compulsory for any c program

Simple C Program /* A first C Program*/ #include <stdio.h> void main(void) {      printf("Hello World"); }

Simple C Program /* A first C Program*/ #include <stdio.h> void main() {      printf("Hello World"); } Header File Preprocessor directive Main Function Opening bracket Statement Part Closing Bracket

Simple C Program Line 1: #include <stdio.h> As part of compilation, the C compiler runs a program called the C preprocessor. The preprocessor is able to add and remove code from your source file. In this case, the directive #include tells the preprocessor to include code from the file stdio.h. This file contains declarations for functions that the program needs to use. A declaration for the printf function is in this file.

Simple C Program Line 2: void main(void) This statement declares the main function. A C program can contain many functions but must always have one main function. A function is a self-contained module of code that can finish some task. The "void" specifies the return type of main. In this case, nothing is returned to the operating system.

Simple C Program Line 3: { This opening bracket denotes the start of the program.

Simple C Program Line 4: printf("Hello World "); Printf is a function from a standard C library that is used to print strings to the standard output, normally your screen. The compiler links code from these standard libraries to the code you have written to produce the final executable. If there were another printf in this program, its string would print on the next line.

Simple C Program Line 5: } This closing bracket denotes the end of the program.

Comment Single line comment // (double slash) – Termination of comment is by pressing enter key Multi line comment /*…. …….*/ It is used to increase the readability of the program. Any number of comments can be given at any place in the program. Comment cannot be nested example: /* A first C Program*/ Comment about the program should be enclosed within /* */ nested comments eg /* to calculate the simple interest /* compound interest */ */ is invalid comment can be split over more than one line eg /* to calculate the simple interest and the compound interest */ This comment statements will be ignored by the compiler while compiling the program, i.e this comment statement won’t be converted to object code. Programming with C 26

Running C Program Type a program Save it Compile the program – This will generate an exe file (executable) Run the program (Actually the exe created out of compilation will run and not the .c file) In different compiler we have different option for compiling and running. We give only the concepts.

The C character Set A character denotes any alphabet, digit or special symbol used to represent information. Alphabets A,B, …. ,Y, Z a,b, ….. ,y, z Digits 0,1,2,3,4,5,6,7,8,9 Special Symbols ~ ‘ ! @ # % ^ & * ( ) _ - + = | \ { } [ ] : ; “ ‘ < > , . ? / Programming with C 28

Constants, Variable and keywords The alphabets, numbers and special symbol when properly combined form constants, variables and keywords A constant is a quantity that doesn’t change A variable is a name given to the location in memory where the constant is stored Example: 3x + y = 20 3 & 20 are constants, which cannot change x & y can vary or change hence are called variables A constant is a quantity that doesn’t change. This quantity can be stored at a locations in the memory of the computer. Eg 3x + y = 20 3 & 20 are constants, which cannot change x & y can vary or change hence are called variables Programming with C 29

Keywords Keywords are the words whose meaning has already been explained to the C compiler Sometimes called reserved words. They cannot be used as variable names. There are only 32 keywords available in c auto double if static do break else int struct goto case enum long switch signed char extern near typedef while const float register union default continue far return unsigned for short void Programming with C 30

Escape Sequence Certain non printing characters can be expressed in terms of escape sequences \n new line \t tab \a alert \\ backslash \” double quote \0 Null \b Backspace

Data Types C Supports several different types of data, each of which may be represented differently within the computers memory. Basic data types are listed below: Data Type Description Typical Memory int integer quantity 2 bytes char single character 1 bytes float floating point number 4 bytes Programming with C 32

Escape Sequences in C Character Escape Sequence Certain non printing characters can be expressed in terms of escape sequences Character Escape Sequence bell \a backspace \b horizontal tab \t vertical tab \v newline \n carriage return \r quotation mark (“) \” question mark(?) \? backslash (\) \\ null \0 Programming with C 33

Development with C Four stages Editing: Writing the source code by using some IDE or editor Preprocessing or libraries: Already available routines compiling: translates or converts source to object code for a specific platform source code -> object code linking: The object code of a program is linked with libraries that are needed for execution of a program. The linker is used to link the program with libraries. It creates a file with '*.exe' extension.

Program Development Editor Preprocessor Compiler Linker Source File Modified Source Code in RAM Compiler Program Object Code File Linker Executable File

Keywords Sometimes called reserved words. Are defined as a part of the C language. Can not be used for anything else! 32 keywords in C Examples: Int void while for