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

Similar documents
DEPARTMENT OF MATHS, MJ COLLEGE

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

6.096 Introduction to C++ January (IAP) 2009

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

UNIT- 3 Introduction to C++

Fundamentals of Programming

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

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

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

Fundamental of Programming (C)

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

Programming and Data Structures

Unit-2 (Operators) ANAND KR.SRIVASTAVA

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

Operators & Expressions

Expressions and Precedence. Last updated 12/10/18

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

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

Operators in java Operator operands.

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

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

Basics of Programming

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

JAVA OPERATORS GENERAL

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

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

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

Operators. Java operators are classified into three categories:

Fundamental of C programming. - Ompal Singh

Infix to Postfix Conversion

C: How to Program. Week /Mar/05

OBJECT ORIENTED PROGRAMMING

Lecture 02 C FUNDAMENTALS

Operators in C. Staff Incharge: S.Sasirekha

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

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

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

A First Program - Greeting.cpp

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

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

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

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

Chapter 2 - Introduction to C Programming

CHAPTER 3 BASIC INSTRUCTION OF C++

Chapter 3: Operators, Expressions and Type Conversion

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )

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

Chapter 2. Lexical Elements & Operators

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

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

.Net Technologies. Components of.net Framework

Department of Computer Science

LECTURE 02 INTRODUCTION TO C++

3. Java - Language Constructs I

VARIABLES AND CONSTANTS

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

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:

BASIC ELEMENTS OF A COMPUTER PROGRAM

Chapter 2: Introduction to C++

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

VARIABLES & ASSIGNMENTS

UNIT-2 Introduction to C++

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators

Data Types and Variables in C language

Information Science 1

Programming in C++ 5. Integral data types

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

Unit 3. Operators. School of Science and Technology INTRODUCTION

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

Review of the C Programming Language for Principles of Operating Systems

CSCE 110 PROGRAMMING FUNDAMENTALS

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

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

CSC 1214: Object-Oriented Programming

Creating a C++ Program

The C++ Language. Arizona State University 1

PYTHON- AN INNOVATION

Basic Elements of C. Staff Incharge: S.Sasirekha

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

Tokens, Expressions and Control Structures

Java Notes. 10th ICSE. Saravanan Ganesh

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

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

Computers Programming Course 5. Iulian Năstac

Data types, variables, constants

Recap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

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

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

Work relative to other classes

2. Distinguish between a unary, a binary and a ternary operator. Give examples of C++ operators for each one of them.

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

Data Types and Variables in C language

Variables. Data Types.

Programming. Elementary Concepts

Transcription:

Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Uppercase Alphabets Lowercase Alphabets Character Set A, B, C, Y, Z a, b, c, y, z Digits 0, 1, 2, 3, 9 Special Symbols White spaces ~! @ # % ^ & * ( ) _ - + = \ { } [ ] : ; " ' < >,.? / Single space, tab, new line.

Token Smallest unit in a program/statement. It makes the compiler understand what is written in the program. Example: main, printf, name,), etc. Tokens are broadly classified as: Identifiers Keywords Constants Variables Strings Operators Special character

Identifiers So to identify things we have some name given to them. Identifiers are the fundamental building blocks of a program Used to give names to variables, functions, constant, and user defined data. They are user-defined names and consist of a sequence of letters and digits

Rules for naming an Identifier

Some Identifiers Tool_spanner; tool_spanner; FORMULA1; engine_1; both are different Wrong identifiers name 1_engine; break; @car-roof;

Keywords Keywords are the reserved words whose meaning has already been explained to the C compiler. We cannot use these keywords as variables. Each keyword is meant to perform a specific function in a C program. There are 32 keywords in C language. All keywords are written in lowercase only Eg: The name of person can never be home, eat, sleep, run, etc because these words have some predefined meaning to perform some task.

List of C Keywords 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

Data Types Data type means the type of value a variable will have. It also defines memory space for a particular variable in computer. The type of value of variable can be alphabets or numbers. The numbers can be further divided as the integer or rational number.

Classification of Data Types In C data type is broadly classified as: Basic data types Derived data types User defined data types

Basic Data Type Integer Character Float Double Derived Data Type Pointers Functions Array User Defined Data Type Structure Union Enumeration Data Type

Type List of Data Types Size (bytes) Minimal range char 1-128 to 127 unsigned char 1 0 to 255 int 2 or 4-32768 to 32767 unsigned int 2 or 4 0 to 65535 short int 2-32768 to 32767 unsigned short int 2 0 to 65535 long int 4-2147483648 to 2147483647 unsigned long int 4 0 to 4294967295 float 4 3.4e-38 to 3.4e+38 with 6 digits of precision double 8 1.7e-308 to 1.7e+308 with 15 digits of precision long double 10 3.4e-4932 to 1.1e+4932 with 20 digits of precision

Constants The entity which do not change throughout the execution are called constants. Types of constants: Integer constant Character constant Floating point constants String constants Name of person remains same through out the life, example: Amit, Shubnam, etc.

Variables Variable is an entity which may change but has a fixed memory location. Variable is used to hold result and reserve memory for the data. datatype variable_name; The naming of variable is done by following the same rules of identifier naming. Eg. What is your hobby? The answer could be reading, dancing, drawing, etc. So the answer to such questions may change during the life time of the person

Rules for naming a Variable 1. An variable name is any combination of 1 to 31 alphabets, digits or underscores. 2. The first character in the variable name must be an alphabet or underscore. 3. No blanks or special symbol other than an underscore can be used in an variable name. 4. Keywords are not allowed to be used as variables.

Expressions Expressions are the statements or the instruction given to computer to perform some operation. Every expression results in some value that can be stored in a variable. Following are few example of expressions in program: Expression to calculate speed of a car. Speed=distance/time Expression to find similarity of two things. c=value1>value2

Expressions in C are basically operators acting on operands. An operand is an entity on which operation is to be performed. Example: addition of two numbers, 5+8, these numbers will be operands. An operator specifies the operation to be applied on operands. Example: The addition, subtraction, etc will be operators Expressions are made of one or more operands. Statements like : a = b + c, ++z 300 > (8 * k)

Operators Operator is the symbol which performs some operations on the operands. 5+5=10 + and = are the operator and 5 and 10 are operands

Types of Operators Types of operators are: 1. Arithmetic operator 2. Unary operator 3. Relational operator 4. Logical operator 5. Assignment operator 6. Conditional operator 7. Bitwise operator 8. Special operator

Arithmetic Operators Description of Operators These are binary operators i.e. expression requires two operands Operator Description + Addition of two operands a + b = 6 - Subtraction of two operands a b = 2 * Multiplication of two operands a * b = 8 / Division of two operands a / b = 2 % Modulus gives the remainder after division of two operands Example (a=4 and b=2) a % b = 0

Unary Operator These operator requires only one operand. Operator Description + unary plus is used to show positive value - unary minus negates the value of operand Example(count=1) +count; value is 1 -count; value is -1 ++ Increment operator is used to ++count; value is 2 increase the operand value by 1 count++; value is 2 -- Decrement operator is used to decrease the operand value by 1 --count; value is 1 count--; value is 1 ++count increments count by 1 and then uses its value as the value of the expression. This is known a prefix operator. count++ uses count as the value of the expression and then increments count by 1. This is known aspostfixoperator.

Relational Operator It compares two operands depending upon the their relation. Expression generates zero(false) or nonzero(true) value. Operator Description Example (a=10 and b=20) < less than, checks if the value of left operand is less (a < b) value is 1(true) than the value of right operand, if yes then condition becomes true. <= less than or equal to, checks if the value of left (a <= b) value is 1 operand is less than or equal to the value of right (true). operand, if yes then condition becomes true. > greater than, checks if the value of left operand is (a > b) value is 0 (not greater than the value of right operand, if yes then true). condition becomes true. >= greater than or equal to, checks if the value of left (a >= b) value is 1 operand is greater than or equal to the value of right (true). operand, if yes then condition becomes true. == equality,checks if the value of two operands is equal or not, if yes then condition becomes true.!= inequality, checks if the value of two operands is equal or not, if values are not equal then condition becomes true. (a == b) value is 0 (not true). (a!= b) value is 1 (true).

Logical Operator It checks the logical relationship between two expressions and the result is zero( false) or nonzero(true). Operator Description && Logical AND operator. If both the operands are true then condition becomes true. Example (5>3 && 5<10) value is 1 (true). Logical OR Operator. If any of the two (5>3 5<2) value is 1 operands is true then condition becomes true. (true).! Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false.!(8==8) value is 0 (false).

Assignment Operator They are used to assign the result of an expression on right side to a variable on left side. Operator Description Example(a=4 and b=2) += a=a+b a+=b; a=a+b = 6 -= a=a-b a-=b; a=a-b = 2 *= a=a*b a*=b; a=a*b = 8 /= a=a/b a/=b; a=a/b = 2 %= a=a%b a%=b; a=a%b = 0 >>= a=a>>b a=00000100 >> 2 = 00010000 <<= a=a<<b A=00000100 << 2 = 00000001 &= a=a&b (a=0100, b=0010) a&=b; a=a&b = 0000 = a=a b (a=0100, b=0010) a =b; a=a b =0110 ^= a=a^b (a=0100, b=0010) a^=b; a=a^b = 0110

Conditional Operator Conditional operator contains condition followed by two statements. If the condition is true the first statement is executed otherwise the second statement. It is also called as ternary operator because it requires three operands. Operator Description?: conditional expression, Condition? Expression1: Expression2 Example (a>b)? a is greater : b is greater

Bitwise Operator A bitwise operator works on each bit of data. Logical Table a b a & b a b a ^ b 0 0 0 0 0 0 1 0 1 1 1 1 1 1 0 1 0 0 1 1 Operator Description Example(a=1 and b=0) & bitwise AND a & b = 0 bitwise OR a b = 1 ^ bitwise XOR a ^ b = 1 ~ bitwise one s complement << bitwise left shift, indicates the bits are to be shifted to the left. >> bitwise right shift, indicates the bits are to be shifted to the right. ~a = 0, ~b=1 1101 << 1 = 1010 1101 >> 1 = 0110

Some Special Operators Operator Description, comma operator, can be used to link the related expressions together sizeof () type sizeof operator to find the size of an object. Cast operator, to change the data type of the variable Example int a, b, x; int a; sizeof(a)=2 float x= 12.5; int a; a = (int) x; value of a is 12.

Precedence of Operators The precedence of operators determine a rank for the operators. The higher an operator's precedence or priority, the higher binding it has on the operands. Example:So how the expression a * b + c will be interpreted? (a * b) + c or a * (b + c), here the first interpretation is the one that is used because the multiplication operator has higher precedence than addition.

Associativity of Operators Associativity tell us the order in which several operators with equal precedence are computed or processed in two directions, either from left to right or vice-versa. Example: In the expression a*b/c, since multiplication and division have the same precedence we must use the associativity to determine the grouping. These operators are left associative which means they are grouped left to right as if the expression was (a*b)/c.

Operator Associativity Type () []. -> ++(postfix) - - (postfix) left to right Highest + - ++ --! & * ~ sizeof (type) right to left Unary * / % left to right multiplicative + - left to right additive << >> left to right shifting < <= > >= left to right relational ==!= left to right equality & left to right bitwise AND ^ left to right bitwise OR left to right bitwise OR && left to right logical AND left to right logical OR?: right to left conditional = += -= *= /= &= = ^= <<= >>= %= right to left assignment, left to right comma

Parts of a C++ Program // sample C++ program #include <iostream> using namespace std; int main() { } beginning of block for main beginning of function named main comment cout << "Hello, there!"; return 0; end of block for main send 0 to operating system string literal preprocessor directive which namespace to use output statement 2-30