DEPARTMENT OF MATHS, MJ COLLEGE

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

Data Types and Variables in C language

Fundamentals of Programming

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

Fundamental of Programming (C)

6.096 Introduction to C++ January (IAP) 2009

Unit-II Programming and Problem Solving (BE1/4 CSE-2)

VARIABLES AND CONSTANTS

UNIT- 3 Introduction to C++

ANSI C Programming Simple Programs

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Programming in C++ 5. Integral data types

Programming and Data Structures

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

C: How to Program. Week /Mar/05

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

BASIC ELEMENTS OF A COMPUTER PROGRAM

Java Notes. 10th ICSE. Saravanan Ganesh

Chapter 2 - Introduction to C Programming

JAVA Programming Fundamentals

Creating a C++ Program

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

Chapter 2: Introduction to C++

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

C Language, Token, Keywords, Constant, variable

UNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

Presented By : Gaurav Juneja

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

PART I. Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++.

Syntax and Variables

Java Programming Fundamentals. Visit for more.

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

Lecture 02 C FUNDAMENTALS

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Basic Elements of C. Staff Incharge: S.Sasirekha

Basics of Programming

Operators in C. Staff Incharge: S.Sasirekha

BCA-105 C Language What is C? History of C

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

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed

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

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Fundamental of C programming. - Ompal Singh

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

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

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:

C/Java Syntax. January 13, Slides by Mark Hancock (adapted from notes by Craig Schock)

C/Java Syntax. Lecture 02 Summary. Keywords Variable Declarations Data Types Operators Statements. Functions. if, switch, while, do-while, for

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

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

CHAPTER 3 BASIC INSTRUCTION OF C++

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

CS102: Variables and Expressions

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

Computers Programming Course 5. Iulian Năstac

C++ character set Letters:- A-Z, a-z Digits:- 0 to 9 Special Symbols:- space + - / ( ) [ ] =! = < >, $ # ; :? & White Spaces:- Blank Space, Horizontal

Lecture 02 Summary. C/Java Syntax 1/14/2009. Keywords Variable Declarations Data Types Operators Statements. Functions

The C++ Language. Arizona State University 1

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

Operators. Java operators are classified into three categories:

LECTURE 02 INTRODUCTION TO C++

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Language Fundamentals Summary

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

C - Basic Introduction

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

Informatics Ingeniería en Electrónica y Automática Industrial

Data types, variables, constants

A flow chart is a graphical or symbolic representation of a process.

C Programming Multiple. Choice

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants

Computer System and programming in C

Computer Programming : C++

Differentiate Between Keywords and Identifiers

Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal

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

C++ Programming: From Problem Analysis to Program Design, Third Edition

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

Objectives. In this chapter, you will:

Introduction to C# Applications

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

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

Overview of C. Basic Data Types Constants Variables Identifiers Keywords Basic I/O

Quick Reference Guide

3. Java - Language Constructs I

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

UNIT-2 Introduction to C++

Operators & Expressions

INTRODUCTION 1 AND REVIEW

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

Programming Lecture 3

Basics of Java Programming

BITG 1233: Introduction to C++

A Fast Review of C Essentials Part I

Transcription:

T. Y. B.Sc. Mathematics MTH- 356 (A) : Programming in C Unit 1 : Basic Concepts Syllabus : Introduction, Character set, C token, Keywords, Constants, Variables, Data types, Symbolic constants, Over flow, under flow, Operators of arithmetic, Relational, Logical, Assignment, Increment and decrement, Conditional and special type. In C-language the English characters are used to write any type of program. Uses small case alphabets of English language a,b,c,------,z. Uses basic nos. from mathematics 0,1,2,3,4,-------,9. Uses diff. types of characters. Such as + plus, minus, * star, / slash, = equal to, % percent,! exclamation, & and,, comma, [ ] { } brackets, : colon,. dot, ; semicolon, # hash, inverted comma C tokens : C tokens are the basic bulidings blocks in C language which are constructed together to write a C program. Each and every smallest individual units in a C program are known as C tokens. C tokens are of six types. They are C tokens example program : main() } { Where, 1. Keywords ( eg. Int, while ) 2. Identifiers ( eg. main, total ) 3. Constants ( eg. 10, 20 ) 4. Strings ( eg. total, Hello ) 5. Special symbols ( eg. (), {} ) 6. Operators ( eg. +,,, / ) Int x, y, total; x = 10, y = 20; total = x + y; printf("total=%d", total); main identifier ( ) { } - special symbol Int - keyword 1

x, y, total identifier Main, (), { }, int, x, y, total C tokens Keywords in C language : There are 32 keywords in C programming language auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void default goto sizeof volatile do if static while Constant : It is a single or multiple digit number formed by using basic numbers whose value Is constant throughout the program. eg. 128, 58.0, 20, - 22.5 The negative number assigned with a negative sign. These are four types of constant used in C language. 1) Float constant : It is a string of number containing decimal values. 2) Integer constant : This constant is a string of numbers. without any decimal values. 3) Exponent constant : The floating point constant can be written in the exponent form if the value is too long or small. 4) Single Character constant : It is constant whose value is a character which may be alphabets number or special character. for eg. 5, a, X 5) String constant : A string constant is a sequence of characters enclosed in double quotes. It consist of any combination of digits, letters, escaped sequences and spaces. for eg. SA, "5+3", "hello". Ex. Following are valid or invalid string constants i) 100 - valid string constant ii) 24, Janpath Road - valid string constant iii) W - invalid string constant iv) Modi - invalid string constant. 2

Difference between single character constant and string constant. Single Character constant Enclosed within single inverted commas The maximum length of a character constant can be one character The character constant A consists of only character A A single character constant occupies one byte. String constant A sequence of characters enclosed in double quotes. A string constant can be any length The character constant A consists of character A and 0. A single string constant occupies two bytes. Variables : A value which varies continuously during the exaction of program in a variable of the program. A variable can be written by a variable name formed by string of alphabets underscore & digits. But the variable name must start with alphabet or underscore. It should not start with digit. The digit can be inserted in the variable name any where. for e.g. sum, piece_ flat, i, number_ of_ movies, whatsapp, hike4 - are valid variable names. Invalid variable names : i) sum value : This is invalid variable due to blank space ii) face book : This is invalid variable due to blank space. iii) 5modi : This is invalid variable because it start with a digit. There are diff. types of variables 1) Integer variable : It is variable whose value during the execution of the program remains as an integer value. This variable can be declared at the starting of the program by the word int eg. int a,b,c; These variable accept the value between 32000 to +32000 2) Float variable: It is a variable name whose value remains real a decimal during execution of the program. This variable name can be declared at the starting of the program by a word float. Eg. float extra, count These variable have up to 6 decimal accuracy. 3) Double variable : This is similar to float variable. It is used when the accuracy provided by a float variable is not sufficient & more accuracy is expected. These are declared by the word double. eg. double second, time; These variable have up to 12 decimal accuracy. 3

4) Character variable: These variable contains a string of alphabets or characters or number as character. These can be declared by using the word char. eg. char call, make These variable accept are character. 5) Long variable: It the word long is placed before any declaration of variable then the declared will be extended accuracy as many computer system for double & integer variable. If long is used for the int variable then the variable accepts the value up to 1 10 21 to 1 10 21 eg. Long int factorial If long is used for the double variable then the variable accept the value up to 24 decimal accuracy. 6) Short variable : If the word short is place before any declaration, then the declared variable will be used to store fairly small accurate value. eg. short int factorial ; 7) Unsigned variable: If the word unsigned is placed before any declaration then the declared variable will be used to store positive number. eg. unsigned int counter; The following are the ranges of variable data types for the variable. Data types char unsigned char Ranges Characters 0 225 char signed char 128 to 127 int 32768 to 32767 unsigned int 0 to 65535 signed int 32768 to 32767 unsigned shot int 0 to 235 sign short int 0 to 235 long int 2147483648 to 2147483647 unsigned long int 0 to 4294967296 singed long int same or long int float double float 6 decimal place 12 decimal place 4

long double float 4 decimal place Symbolic Constant : A symbolic constant is same that substitute for a sequence of character that can t be changed. The character may represent a numeric constant, a character constant or a string. When the program is compiled each occurrence of a symbolic constant is replaced by its corresponding character sequence. They are usually define at the beginning of the program. The symbolic constant may then appear later in the program in place of the numeric constants, character constant etc. that the symbolic constant represent. for eg : C program consists of the following symbolic constant define PI 3.142 define TRUE 1 define FALSE 0 Overflow : In C programming an integer overflow occurs when an arithmetic operation attempts to create a numeric value that is too large to be represented within the available storage space. For instance, adding 1 to the largest value that can be represented constitutes an integer overflow. Underflow : The condition in a C program that can occur when the true result of a floating point operation is smaller in magnitude ( that is closer to zero ) than the smallest value representable as a normal floating point number in the target data type. Arithmetic operators : The arithmetic operators perform arithmetic operations and can be classified in to unary and binary arithmetic operations. The following are the list of the arithmetic operators. Operator Meaning + Addition _ Minus * Multiplication / Division % Modulus 1) Unary minus operators : If the value of any variable is negative then it is assigned with a negative sign by the use of unary minus operators. eg : a ; where negative sign is a unary minus operator. 2) Modulus operator : The modulus operator is indicated by % sign. This operator provides as a reminder of any value between divisions of the two integer variable. eg. a%b. This means that a is divided by b & remainder is the result. Relational Operators : The relational operators are used to compare arithmetic, logical and character expressions. We often compare two quantities and depending upon that we take a decision. 5

Operator Meaning < less than > greater than <= less than or equal to >= greater than or equal to == equal to! = not equal to Logical operator : These operators are used to compare the logical and relational expressions. Operator Meaning && Logical AND Logical OR! Logical NOT Bitwise operator : These operators operate on each bit of data. They are used for testing, complementing or shifting of bits to right or left. Usually they are not useful in the case of float and double variables. Operator Meaning & bitwise AND bitwise OR ^ Bitwise XOR Shift left Shift right ~ Bitwise complement Assignment Operator : This operator evaluates the expression on the right and assigns the resulting value to the variable on the left side. " = " is called as assignment operator. Increment and Decrement Operators : These operators are very much used in C language. They are extensively used in loops Syntex : Increment : ++< variable name > < variablename > + + Decrement : < variable name > < variablename > The + + operator adds 1 to the operand and operator subtract 1 from the operand. Conditional Operator : This operator consists of two symbols : the question mark (? ) and colon ( : ) Syntax : variable = (test expression)? true: false; It has three components the expression, true part and false part. If the expression is true it evaluates to true part after? else it evaluates false part after colon. Method of writing C program : Every column of screen accepts one character on one line. Each character of the statement should be written on one line on the program. At the end of every statement semicolon ; must be provided. Which indicates that the statement is complete. If the space for statement is not sufficient, it can be written an next line. The statement instruction should be written in continuation of the 6

sequence of the statement. If the program is a main program then it is to be written by the first statement as main ( ) main ( ) - main program { - start of program - Program statement } - end of program The opening { brace denotes the start of the program an one line & written below main ( ) statement. The statement are inserted after opening brace & at the end of program. It is closed by } closing brace on one single line.. Comment statement : The comment statement is enclosed in the two states / with * on both sides of the statement is useful for the reading of the program by the operator. It can be used for giving a tittle to the program. The comment statement can be inserted any where in the program. It is non-executable statement of the program. Eg. /* India is my country */ Ex.1] Explain whether following variable names are valid or invalid, if invalid why? 1) n_3_5 valid 2) 5-next invalid because it start with digit. 3) x > y 8 invalid due to > symbol. 4) w.l.o. invalid due to. symbol. 5) x$ invalid due to special symbol $ 6) y invalid due to special symbol Xl. 7) beg invalid due to 8) _beg valid 9) raman valid 10) Raman invalid due to start with capital letter. Ex.2] Correct the following statement in C. 1) float c, d Sol: correct is float c, d; 2) int a, b float c; Sol: correct is int a, b, float c; 3) /* This is a c program. 7

Sol: correct /* This is a c program */ 4) c = ((a + b) c)/d Sol: correct c = ((a + b) c)/d; 5) int a, b, c; sol: correct is int a, b, c; 6) / This is a best program */ Sol: correct /* This is a best program */ Ex.3. Write a C program to print our name with comment statement /* write a program to print our name */ main( ) } { printf ( my name is xyz ); Output: my name is xyz Ex.4 Write a C program to print Hi I am using whatsaap with comment statement. /* write a program to print Hi I am using whatsaap */ main( ) } { printf ( Hi I am using whatsaap ); Output: I am using whatsaap ( 1 mark questions ) Exercise 1. State whether the following statements are TRUE or FALSE : i) Every line in a C program should end with a semicolon. ii) Every C program ends with an END word. iii) In C language, lowercase letters are significant. iv) A line in a C program may have more than one statement. v) The closing brace of the main( ) in a program is the logical end of the program. 2. Write any four keywords in C language. 3. How many keywords in C languages, write any two keywords. 4. Following constant are which type of constant. i) 20, 37.45 8

ii) a, hello 5. Define string constant. 6. Define single character constant. 7. How to write the comment statement in C. 8. Write the syntax of Increment. 9. Write the syntax of decrement. 10. Write the syntax of conditional operator. ( 2 marks questions ) 1. Write types of C tokens. 2. Write any eight keywords in C language. 3. Write types of constant in C. 4. Write types of variable in C. 5. Define string constant. Give some example? 6. Write any two difference between single character constant and string constant. 7. Define symbolic constant 8. Write any two arithmetic operator and their meaning in C. 9. Write any two logical operator and their meaning in C. 10. Write any two relational operator and their meaning in C. 11. Write the syntax of Increment and decrement. 12. Write the syntax of conditional operator and its meaning. ( 3 marks questions ) 1. Write short note on C tokens. 2. Write short note on keywords in C language. 3. Write short note on constant in C. 4. Write short note on variable in C. 5. Write short note on arithmetic operator in C. 6. Explain the method of writing C program 9