C++ is case sensitive language, meaning that the variable first_value, First_Value or FIRST_VALUE will be treated as different.

Similar documents
UNIT- 3 Introduction to C++

CHAPTER-6 GETTING STARTED WITH C++

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

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

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

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

CSC 1107: Structured Programming

DEPARTMENT OF MATHS, MJ COLLEGE

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

Lecture 3. More About C

Java Notes. 10th ICSE. Saravanan Ganesh

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

JAVA OPERATORS GENERAL

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

6.096 Introduction to C++ January (IAP) 2009

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

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

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

JAVA Programming Fundamentals

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

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

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

Fundamental of Programming (C)

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

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

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

Basics of Programming

Introduction to C# Applications

C: How to Program. Week /Mar/05

Expression and Operator

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

Chapter 12 Variables and Operators

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

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

Lecture 02 C FUNDAMENTALS

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

Chapter 2 - Introduction to C Programming

Java Basic Datatypees

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

Chapter 2. Lexical Elements & Operators

Chapter 12 Variables and Operators

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Lecture 2 Tao Wang 1

Language Fundamentals Summary

Differentiate Between Keywords and Identifiers

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

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

Prof. Navrati Saxena TA: Rochak Sachan

LEXICAL 2 CONVENTIONS

Variables and literals

Creating a C++ Program

Computers Programming Course 5. Iulian Năstac

BITG 1233: Introduction to C++

Room 3P16 Telephone: extension ~irjohnson/uqc146s1.html

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

Operators in C. Staff Incharge: S.Sasirekha

Chapter 2: Introduction to C++

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

C Programming Multiple. Choice

Basic Elements of C. Staff Incharge: S.Sasirekha

BASIC ELEMENTS OF A COMPUTER PROGRAM

Computers Programming Course 6. Iulian Năstac

Fundamental of C programming. - Ompal Singh

Fundamentals of Programming

Unit 3. Operators. School of Science and Technology INTRODUCTION

Work relative to other classes

XC Specification. 1 Lexical Conventions. 1.1 Tokens. The specification given in this document describes version 1.0 of XC.

Chapter 2: Using Data

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

Chapter 1. Principles of Object Oriented Programming

Java Programming Fundamentals. Visit for more.

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

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

L-System Fractal Generator: Language Reference Manual

LECTURE 02 INTRODUCTION TO C++

Basic Source Character Set for C++ Language:

4 Programming Fundamentals. Introduction to Programming 1 1

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

ME240 Computation for Mechanical Engineering. Lecture 4. C++ Data Types

Unit-2 (Operators) ANAND KR.SRIVASTAVA

SECTION II: LANGUAGE BASICS

Types, Operators and Expressions

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

Basics of Java Programming

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

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

Standard 11. Lesson 9. Introduction to C++( Up to Operators) 2. List any two benefits of learning C++?(Any two points)

Lexical Considerations

2 nd Week Lecture Notes

GridLang: Grid Based Game Development Language Language Reference Manual. Programming Language and Translators - Spring 2017 Prof.

Types, Operators and Expressions

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

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

Operators in java Operator operands.

Reserved Words and Identifiers

COMS W4115 Programming Languages & Translators GIRAPHE. Language Reference Manual

C - Basic Introduction

Information Science 1

BRAIN INTERNATIONAL SCHOOL. Term-I Class XI Sub: Computer Science Revision Worksheet

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

Transcription:

C++ Character Set a-z, A-Z, 0-9, and underscore ( _ ) C++ is case sensitive language, meaning that the variable first_value, First_Value or FIRST_VALUE will be treated as different. Identifier and Keywords: Identifiers in C++ are used to give names to various elements in a program like variable, constants, functions and arrays etc. One must give the name to an identifier as per its usage. Keywords are identifiers that are reserved words in C++ and have specific purpose. These reserved cannot be used by the user as user defined identifiers. C++ has 34 keywords. Escape Sequence in C++ An escape sequence is a sequence of characters that does not represent itself when used inside a character or string literal, but is translated into another character or a sequence of characters that may be difficult or impossible to represent directly. In C/C++, all escape sequences consist of two or more characters, the first of which is the backslash, \; the remaining characters determine the interpretation of the escape sequence. The escape sequence are given below: Escape sequence Character Action \a Bell/beep Sound a beep \b backspace Moves cursor one back space \f formfeed Next line \n newline Next line \t tab Horizontal tab \r return Return \ \ backslash For comment statement \ Single quote \ Double quote \xdd hexadecimal Base 16 \o Null character \? Question mark \xhhh Hexa decimal value such as \x1b \ooo Octal value such as \ o33 The escape can be used in cout statement within the as cout<< \n enter a number ; //This statement will print enter a number on new line

Data Types in C++ Data type in a programming language is used to assign a type of value to a variable from the range of the values supported by that type. For example a data type char can be used to assign any one of the character set defined in C++ to a variable. They are of the following types: Data types in C++ Memory Data Type Minimum Value Maximum Value (ByteS) Bool 1 Logical Value T/F Logical Value T/F Char 1-128 127 Unsigned Char 1 0 255 Short 2-32768 32767 Unsigned Short 2 0 65535 Int 2-32768 32767 unsigned int 2 0 65535 Long 4-2147483648 2147483647 unsigned long 4 0 4294967295 Float 4 10-38 10 38 Double 8 10-308 10 308 long double 10 10-4932 10 4932

Token in C++ Keywords: have their meaning predefined in C++. They cannot be used by programmer for any other purpose. Identifiers: Are the name of the user defined variables, arrays, functions etc Variables: Constants: Are whose value cannot change during the execution of the program. Constants in C++ Constants in c++ are the data elements which do not change throughout the execution of the program. Constants can be of following type: Integer constant : 7, 3, 10, 345 etc Character constant : A, Z, x etc Float constant : 0.2, 0.34, 2.35 String constant : RAM, XYZ Expression Vs. Statement Expression X=2+3 Statement X=2+3; Not terminated by semicolon (;) Always terminated by semicolon (;) Operators in C++

An operator in C++ is used to perform an operation on the operand(s) and part of an expression. For example c= a+b; here there are two operators; one the + arithmetica addition operates which evaluates the sum of a and b, and the other is = equivality operator which is used to assign the value to the left hand side operand. Operators in C++ are of the following types. 1. Assignment Operator 2. Mathematical Operators 3. Relational Operators 4. Logical Operators 5. Bitwise Operators 6. Shift Operators 7. Unary Operators 8. Ternary Operator 9. Comma Operator Arithmetic Operators Assignment Operators Relational Operators logical operators Bit wise logical operators Shift Operator AND (&&), OR ( ), NOT(!) Used to combine two operands, for AND validity of both statements will be considered, for OR( ) validity of 2 nd statement is considered if 1 st statement is invalid +, -, *, /, % and, or, xor, not &,, ^, ~ =, +=, -=, *=, %=, /=, >>=, <<=, &=, =, ^= >, >=, <, <=,!=, == These operators are mostly used in loops (especially while loop) and in Decision making. Right Shift, left Shift, unsigned >>, <<, >>>> right shift Unary Operator increment, decrement, Address ++, --, &, *, -, &, ~,! of, dereference, unary -, bitwise NOT, logical NOT, new, delete Ternary If-else? : Example int a = 10; a > 5? cout << "true" : cout << "false" Comma Operator Used to separate : variable names and expressions int a,b,c; // variables declaration using comma operator

a=b++, c++; // a = c++ will be done. Operator Precedence Unary Operator Sizeof( type) ++ - L to R Highest Arithmetic * / % L to R Multiply, divide and remainder Arithmetic Add, Sub + - L to R Relational < <= > >= L to R Operator Equality ==!= L to R Logical and && L to R Conditional?: L to R Assignment %= /+= *= - = + = = L to R Operator Lowest Z = -10/5 20 + 8 = -2-22 +8 = -16 Use of Operator (a) Unary Operators : Sizeof(type), ++ and #include<iostream.h> #include<conio.h> void main() { clrscr(); int a,b; float c; cout<<"enter twointeger number"<<endl; cin>>a>>b; cout<<"enter a float number"<<endl;

} cin>>c; cout<<"size of int "<<a<<"is=\t\t"<<sizeof(a)<<"bytes"<<endl; cout<<"size of int "<<b<<"is=\t\t"<<sizeof(b)<<"bytes"<<endl; cout<<"size of float "<<c<<"is=\t"<<sizeof(c)<<"bytes"<<endl; a++; b++; c++; cout<<endl<<"++ operator give values of a, b, c are:"<<endl<<a<<"\t"<<b<<"\t <<c<<endl; cout<<"unary - give a, b and c as "<<-a<<",\t"<<-b<<" and\t "<<-c<<endl; getch(); (b) Arithmetic Multiply(*), Divide(/), Mod(%), Add(+) and Sub(-) Operator #include<iostream.h> #include<conio.h> void main() { clrscr(); int temp,a,b,c,d,n,sum; cout<<"enter four digit number:\t"; cin>>n; temp=n; a=n%10; n=n/10; b=n%10; n=n/10; n=n/10; d=n%10;

} sum=d+c+b+a; cout<<"\nthe sum of the digits of number = "<<temp<<" is=\t"<<sum; getch(); (c) Ternary Operator: A ternary operator is a conditional operator. If a particular condition is met then the first value after the ternary operator is returned other wise the second value after the, is returned. #include<iostream.h> #include<conio.h> #include<iomanip.h> void main() { clrscr(); int a,b,n,c; cout <"\nprogram enters n, a, and b integers\n"; cout<<"and returns a if n>10 else b"<<endl; cout<<"enter any number:\t"; cin>>n>>a>>b; c= n > 10? a : b; cout<<"\n number = "<<n<<"and returned =\t"<<c; getch(); } Bit wise logical operators (AND(&), OR( ), XOR(^), NOT(~))

#include<iostream.h> #include<conio.h> #include<iomanip.h> void main() { clrscr(); int a,b,c,d,e,f; cout<<"enter two numbers\n"; cin>>a>>b; c= a & b; d= a b; e=a ^ b; f= ~a; cout<<"\n bitwise and(&) of"<<a <<" and "<<b<<" is = "<<c<<endl; cout<<"\n bitwise or ( ) of "<<a <<" and "<<b<<" is = "<<d<<endl; cout<<"\n bitwise xor (^) of"<<a <<" and "<<b<< " is = "<<e<<endl; cout<<"\n bitwise NOT (~) of"<<a << " is = "<<f<<endl; getch(); }