Introduction to C programming. By Avani M. Sakhapara Asst Professor, IT Dept, KJSCE

Similar documents
Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

ME 172. Lecture 2. Data Types and Modifier 3/7/2011. variables scanf() printf() Basic data types are. Modifiers. char int float double

Presented By : Gaurav Juneja

Differentiate Between Keywords and Identifiers

Preview from Notesale.co.uk Page 6 of 52

Computers Programming Course 5. Iulian Năstac

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

Fundamental of C programming. - Ompal Singh

Programming in C and Data Structures [15PCD13/23] 1. PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme]

Fundamentals of C Programming

C Language, Token, Keywords, Constant, variable

Data Types and Variables in C language

VARIABLES AND CONSTANTS

1.1 Introduction to C Language. Department of CSE

Introduction to Computing Lecture 01: Introduction to C

The component base of C language. Nguyễn Dũng Faculty of IT Hue College of Science

These are reserved words of the C language. For example int, float, if, else, for, while etc.

Today. o main function. o cout object. o Allocate space for data to be used in the program. o The data can be changed

C - Basic Introduction

CS149: Elements of Computer Science. Fundamental C++ objects

Tutorial No. 2 - Solution (Overview of C)

Basic Elements of C. Staff Incharge: S.Sasirekha

ME 172. Sourav Saha. Md. Mahamudul Hossain Kazi Fazle Rabbi Saddam Hossain Joy Kamruzzaman Lecturer,Dept. of ME,BUET

Programming and Data Structures

Guide for The C Programming Language Chapter 1. Q1. Explain the structure of a C program Answer: Structure of the C program is shown below:

Basics of Programming

BLM2031 Structured Programming. Zeyneb KURT

P.E.S. INSTITUTE OF TECHNOLOGY BANGALORE SOUTH CAMPUS 1 ST INTERNAL ASSESMENT TEST (SCEME AND SOLUTIONS)

Lab Session # 1 Introduction to C Language. ALQUDS University Department of Computer Engineering

Work relative to other classes

6.096 Introduction to C++ January (IAP) 2009

.. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar..

CC112 Structured Programming

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

Intro to Computer Programming (ICP) Rab Nawaz Jadoon

C Fundamentals & Formatted Input/Output. adopted from KNK C Programming : A Modern Approach

MA 511: Computer Programming Lecture 2: Partha Sarathi Mandal

DECLARATIONS. Character Set, Keywords, Identifiers, Constants, Variables. Designed by Parul Khurana, LIECA.

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

CS242 COMPUTER PROGRAMMING

IECD Institute for Entrepreneurship and Career Development Bharathidasan University, Tiruchirappalli 23.

Chapter 1 & 2 Introduction to C Language

Fundamentals of Programming

Department of Computer Applications

Computer System and programming in C

Materials covered in this lecture are: A. Completing Ch. 2 Objectives: Example of 6 steps (RCMACT) for solving a problem.

CSc Introduction to Computing

DEPARTMENT OF MATHS, MJ COLLEGE

C LANGUAGE AND ITS DIFFERENT TYPES OF FUNCTIONS

AMCAT Automata Coding Sample Questions And Answers

Chapter 2. Lexical Elements & Operators

A Fast Review of C Essentials Part I

Fundamentals of Programming Session 4

INTRODUCTION 1 AND REVIEW

CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE

Course Outline Introduction to C-Programming

Fundamental of Programming (C)

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

Variables in C. Variables in C. What Are Variables in C? CMSC 104, Fall 2012 John Y. Park

Number Systems, Scalar Types, and Input and Output

C: How to Program. Week /Mar/05

Full file at C How to Program, 6/e Multiple Choice Test Bank

CSCI 2132: Software Development. Norbert Zeh. Faculty of Computer Science Dalhousie University. Introduction to C. Winter 2019

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Basic Science and Humanities

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

Computer Programming : C++

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

!"#$% &'($) *+!$ 0!'" 0+'&"$.&0-2$ 10.+3&2),&/3+, %&&/3+, C,-"!.&/+"*0.&('1 :2 %*10% *%7)/ 30'&. 0% /4%./

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

EC 413 Computer Organization

Unit 1: Introduction to C Language. Saurabh Khatri Lecturer Department of Computer Technology VIT, Pune

LECTURE 02 INTRODUCTION TO C++

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Chapter 2 - Introduction to C Programming

C Programming Multiple. Choice

Basic Types and Formatted I/O

I Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs.

EL2310 Scientific Programming

CSCI 2132 Software Development. Lecture 8: Introduction to C

CMSC 246 Systems Programming

SEQUENTIAL STRUCTURE. Erkut ERDEM Hacettepe University October 2010

Lecture 2 Tao Wang 1

UNIT- 3 Introduction to C++

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

ANSI C Programming Simple Programs

Fundamentals of Programming. Lecture 3: Introduction to C Programming

CS102: Variables and Expressions

Week 3 Lecture 2. Types Constants and Variables

CSCE 110 PROGRAMMING FUNDAMENTALS

ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1

Gabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming

Computational Expression

printf( Please enter another number: ); scanf( %d, &num2);

Programming in C++ 4. The lexical basis of C++

CS10001: Programming & Data Structures. Dept. of Computer Science & Engineering

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

Sir Syed University of Engineering and Technology. Computer Programming & Problem Solving ( CPPS )

Transcription:

Introduction to C programming By Avani M. Sakhapara Asst Professor, IT Dept, KJSCE

Classification of Software Computer Software System Software Application Software

Growth of Programming Languages

History ALGOL 60 too abstract and generic CPL (Combined Programming Language) at Cambridge University too big, many features, difficult to learn and implement BCPL (Basic Combined Programming Language) at Cambridge university by Martin Richards too specific, less powerful B language at AT & T s Bell Lab by Kem Thompson too specific C language = B language + BPCL + new features C language at AT & T s Bell Lab in USA by Dennis M. Ritchie in 1972

Features of C Robust language can be used to write any complex program Has rich set of built-in functions and operators well suited for writing both, system s/w and application s/w Dynamic Allocation of Memory

Structure of a C Program #include<stdio.h> /*multiline Comment*/ void main() { //single line comment printf( Hello all ); } #include->preprocessor directive stdio.h->standard input output header file which has printf function program execution always start from main() function printf() function is used to display some text on the output screen

Structure of a C Program #include<stdio.h> /*multiline Comment*/ void main() { //single line comment printf( Hello all ); }

Escape Characters These are non-printing characters and are represented by escape sequences consisting of a backslash (\) followed by a letter

List of Escape Characters

Exercise Write a C program to display the following 1. Display the below message Favourite colour: yellow 2. Display the table Roll no Class Div 123 SE A 124 FE B

Variables A variable is an entity used by the program to store values used in the computation Variable names are the names given to the memory location where the values are stored. The type of the variable depends on the type of the value it stores.

Rules for forming variable names It should begin with a letter or underscore( _ ) Followed by any combination of letters, underscores and digits 0-9 Eg: sum, item_price1, _sys valid names price$, #num invalid names The uppercase and lowercase letters are distinct in C. The variable names sum and Sum refers to different variables No commas or blank spaces allowed Length of variables depends on the compiler

Data types

Primary Data Types Data type keyword Size(in bytes) Range Purpose Format Specifier Character char 1-2 7 to 2 7-1 Store single = -128 to +127 character %c Integer int 2-2 15 to 2 15-1 = -32768 to +32767 Store numbers %d Float float 4-3.4e38 to +3.4e38 Store fractions Double double 8-1.7e308 to +1.7e308 Store smaller fractions %f %lf

Qualifiers Qualifiers can be used with basic datatypes short and long vary the size - short->used with int - long-> used with int and double signed and unsigned vary the range - used with char and int

Data type with qualifier signed short int /short int/int signed long int/long int/long unsigned short int /unsigned short/unsigned int unsigned long int/unsigned long Data types with Qualifiers Size(in bytes) Range Purpose Format Specifier 2-2 15 to 2 15-1 = -32768 to +32767 4-2 31 to 2 31-1 Store large numbers 2 0 to 2 16-1 =0 to 65535 Store numbers %d store positive numbers and zero 4 0 to 2 32-1 store large positive numbers and zero unsigned char 1 0 to 2 8 1 =0 to 255 store positive bytes long double 10 store small fractional values %ld %u %lu %c %Lf

Variable Declaration and Initialization All the variables must be declared at the beginning of the function before using it. Syntax: datatype var1, var2; Eg: int number, sum; float interest; Variable Initialization: var1=value1; var2=value2; Eg: number = 23; interest = 2.3f;

Variable Declaration and Initialization Variables can be initialized at the time of variable declaration using the following Syntax: datatype var1= value1; Eg: int number = 23;

Specifications of Different Constants

Example: Program to add two #include<stdio.h> void main() { int a, b=6, c; a=3; c = a + b; printf( sum = 9 ); printf( sum = %d, c); } numbers #include<stdio.h> void main() { int a, b=6, c; a = 3; printf( sum = %d, a + b); }

Using scanf() for input scanf() function is defined in <stdio.h> header file Syntax: scanf( format specifier,&varname); &varname address of(&) varname Eg: scanf ( %d,&a); Getting multiple values using scanf() - scanf ( %d %f, &a, &b);

Excercise Write a C program to accept two numbers from the user and swap them using i) third variable ii) Without using third variable Write a C program to accept the radius of the circle from the user and calculate the circumference and the area of the circle and display it.

Defining Constants Two ways for defining constants i) Using #define directive ii) Using const keyword 1) Using #define directive Syntax: # define identifier token-string The directive substitutes token-string for all subsequent occurrences of an identifier Called symbolic constants Usually written in uppercase to differentiate it from variables

Examples # include<stdio.h> #define SIZE 5 void main() { int a=3; //SIZE replaced by 5 a = SIZE * 2; printf( result= %d, a); SIZE= 10; //error } # include<stdio.h> void main() { const int size = 5; int a=3; //size replaced by value 5 a = size * 2; printf( result= %d, a); size= 10; //error }