C++ Language
By : Shrirang Pinjarkar
Email : shrirang.pinjarkar@gmail.com
UNIT -2
DATA TYPES ,
VARIABLES AND
OPERATORS
Overview
Objectives
C++ data types, constant and variable
C++ keywords
Input Output : cin, cout
Hands On!
DATA TYPE
 A data type determines the type of the
data that will be stored, usually, in the
computer memory (RAM).
 Type statements in C++ are used to allow
the compiler to:
 reserve blocks of memory to store information
 give the reserved blocks of memory a symbolic
name so that the data contained in this block of
memory can be manipulated by referring to this
name in future C++ statements.
Data Types
C++ provides three fundamental data types:
- int (integers ) ex: 1 , -8 ,0 ,etc
- float (decimal numbers) ex: 2.03 , -7.15 , 0.0 , etc
- char (character) ex: ‘a’ , ‘A’ , ‘1’, etc
0 is not float
0.0 is float
Name Description Size* Range*
char Character 1byte
signed: -128 to 127
unsigned: 0 to 255
short int
(short)
Short Integer. 2bytes
signed: -32768 to 32767
unsigned: 0 to 65535
int Integer. 2 or 4 bytes
signed: -2147483648 to
2147483647
unsigned: 0 to
4294967295
long int
(long)
Long integer. 4bytes
signed: -2147483648 to
2147483647
unsigned: 0 to
4294967295
bool
Boolean value. It can take
one of two values: true or
false.
1byte true or false
float Floating point number. 4bytes +/- 3.4e +/- 38 (~7 digits)
double
Double precision floating
point number.
8bytes
+/- 1.7e +/- 308 (~15
digits)
long double
Long double precision
floating point number.
8bytes
+/- 1.7e +/- 308 (~15
digits)
Exercise
 What is the suitable data type for the following?
 number of student in your class - unsigned int
 your matrix elements - float
 assignment marks for this subject - float
 the distance to the moon (the distance to the moon is over 200,000
miles) - long double
 last month's checking account balance - float /double
 a counter used to count the number of lines in a text file - int
 number of people living in Malaysia - long
 the temperature used in a chemistry formula - float
Variables
variable
 a valid identifier whose value can change during the course
of execution of a program
general form of the declarations:
data-type variable_name;
example:
int mass;
double x, speed, dragForce;
Declaration of Variables
when a variable is declared, you can initialize it in
two alternative but equivalent ways
int mass = 22;
or
int mass; //(garbage value)
mass = 22;
Declaration of string variable
example:
string name = “Mohamad”;
Variables
// Declaration of variables
#include <iostream>
using namespace std;
int main ()
{
short x = 22, y = 11, z;
z = x - y;
cout << "z = " << z << endl;
int p = 3;
int q = x * y * z - 2 * p;
cout << "q = " << q << endl;
return 0;
}
Exercise :
Correct the following errors
 long Float x; long x;
 int code = three, int code = 3;
 const int array size; const int array_size;
Declare the following variable:
Name Type Initial value
marks double None
grade char A
price float 10.0
num_1 int 5
msg string Hello World
result bool true
Scope of Variable
variable can have either local or global
scope
scope (visibility) of local variables is
limited to the block enclosed in braces
({ }) where they are declared
global variables are declared outside of
all blocks and their scope are the entire
program, i.e. the main body of the
source code.
What is the Scope of A
variable ?
Scope refers to the visibility of variables. In
otherwords, which parts of your program can see
or use it. Normally, every variable has a global
scope. Once defined, every part of your program
can access a variable.
A scope is a region of the program and broadly speaking there
are three places, where variables can be declared:
Inside a function or a block which is called local
variables,
In the definition of function parameters which is called
formal parameters.
Outside of all functions which is called global
variables.
Operators in C++
An operator is a symbol that tells the compiler to
perform specific mathematical or logical
manipulations. C++ is rich in built-in operators
and provides the following types of operators:
Arithmetic Operators
Relational Operators
Logical Operators
Bitwise Operators
Assignment Operators
Arithmetic Operators:
Assume variable A holds 10 and variable B holds 20
Operat
or
Description Result
+ Adds two operands 30
- Subtracts second operand from first -10
* Multiplies both Operands 200
/ Divides numerator by De-numerator B/A=2
% Modulus Operator and reminder of after
integer division
A%B=0
++ Increment operator , increases integer value
by one
11 A++
-- Decrement Operator, Decreases Integer
Value by One
9
7/8/2014
By Himanshu Kaushik |
ApplicationDeveloper.in |
Himanshukaushik.in
main()
{
int a = 21;
int b = 10;
int c ;
c = a + b;
cout << "Line 1 - Value of c is :" << c << endl ;
c = a - b;
cout << "Line 2 - Value of c is :" << c << endl ;
c = a * b;
cout << "Line 3 - Value of c is :" << c << endl ;
c = a / b;
cout << "Line 4 - Value of c is :" << c << endl ;
c = a % b;
cout << "Line 5 - Value of c is :" << c << endl ;
c = a++;
cout << "Line 6 - Value of c is :" << c << endl ;
c = a--;
cout << "Line 7 - Value of c is :" << c << endl ;
return 0;
Relational Operators
Assume variable A holds 10 and variable holds 20
Operato
r
Description Example
== Checks if the Value of two Operands are
Equal or not , if yes then condition
becomes True
(A==B) is not
true
!= Checks if the value of two operands are
equal or not , if values are not equal then
condition becomes true
(A!=B) is true
> Checks if the value of Left operand is
greater than the value of right operand , if
yes then condition becomes true,
(A>B) is not true
< , >= , <= are relationals operators
Bitwise Operators
Bitwise operator works on bits and perform bit-by-bit
operation.
P Q P & Q P|Q P^Q
0 0 0 0 0
0 1 0 1 1
1 1 1 1 0
1 0 0 1 1
if A = 60; and B = 13
Assume if A = 60; and B = 13; now in binary
format they will be as follows:
 A = 0011 1100
 B = 0000 1101
 A&B = 0000 1100
 A|B = 0011 1101
 A^B = 0011 0001
 ~A  = 1100 0011
Operato
r
Description Result
& Binary AND Operator copies a bit
to the result if it exists in both
operands.
(A & B) will give 12
which is 0000 1100
| Binary OR Operator copies a bit if
it exists in either operand.
(A | B) will give 61
which is 0011 1101
^ Binary XOR Operator copies the
bit if it is set in one operand but
not both.
(A ^ B) will give 49
which is 0011 0001
Operato
r
Description Result
~ Binary Ones Complement Operator
is unary and has the effect of
'flipping' bits.
(~A ) will give -61
which is 1100 0011 in
2's complement form
due to a signed binary
number.
<< Binary Left Shift Operator. The left
operands value is moved left by the
number of bits specified by the right
operand.
A << 2 will give 240
which is 1111 0000
>> Binary Right Shift Operator. The
left operands value is moved right
by the number of bits specified by
the right operand.
A >> 2 will give 15
which is 0000 1111
By Himanshu Kaushik |
ApplicationDeveloper.in |
Himanshukaushik.in
main()
{
unsigned int a = 60; // 60 = 0011 1100
unsigned int b = 13; // 13 = 0000 1101
int c = 0;
c = a & b; // 12 = 0000 1100
cout << "Line 1 - Value of c is : " << c << endl ;
c = a | b; // 61 = 0011 1101
cout << "Line 2 - Value of c is: " << c << endl ;
c = a ^ b; // 49 = 0011 0001
cout << "Line 3 - Value of c is: " << c << endl ;
c = ~a; // -61 = 1100 0011
cout << "Line 4 - Value of c is: " << c << endl ;
c = a << 2; // 240 = 1111 0000
cout << "Line 5 - Value of c is: " << c << endl ;
c = a >> 2; // 15 = 0000 1111
cout << "Line 6 - Value of c is: " << c << endl ;
Assignment Operators
By Himanshu Kaushik |
ApplicationDeveloper.in |
Himanshukaushik.in
Operator Description Example
= Simple assignment
operator, Assigns values from right
side operands to left side operand
C = A + B will
assign value of A
+ B into C
+= Add AND assignment operator, It
adds right operand to the left
operand and assign the result to left
operand
C += A is
equivalent to C =
C + A
-= Subtract AND assignment operator,
It subtracts right operand from the
left operand and assign the result to
left operand
C -= A is
equivalent to C =
C - A
Assignment Operators
Operator Description Example
*= Multiply AND assignment operator, It
multiplies right operand with the left
operand and assign the result to left
operand
C *= A is
equivalent to C =
C * A
/= Divide AND assignment operator, It
divides left operand with the right
operand and assign the result to left
operand
C /= A is
equivalent to C =
C / A
%= Modulus AND assignment operator,
It takes modulus using two operands
and assign the result to left operand
C %= A is
equivalent to C =
C % A
7/8/2014
By Himanshu Kaushik |
ApplicationDeveloper.in |
Himanshukaushik.in
main()
{
int a = 21;
int c ;
c = a;
cout << "Line 1 - = Operator, Value of
c = : " <<c<< endl ;
c += a;
cout << "Line 2 - += Operator, Value of
c = : " <<c<< endl ;
c -= a;
cout << "Line 3 - -= Operator, Value of
c = : " <<c<< endl ;
c *= a;
cout << "Line 4 - *= Operator, Value of
c = : " <<c<< endl ;
c /= a;
cout << "Line 5 - /= Operator, Value of
c = : " <<c<< endl ;
c = 200;
c %= a;
cout << "Line 6 - %= Operator, Value of
c = : " <<c<< endl ;
c <<= 2;
cout << "Line 7 - <<= Operator, Value
of c = : " <<c<< endl ;
c >>= 2;
cout << "Line 8 - >>= Operator, Value
of c = : " <<c<< endl ;
c &= 2;
cout << "Line 9 - &= Operator, Value of
c = : " <<c<< endl ;
c ^= 2;
cout << "Line 10 - ^= Operator, Value of
c = : " <<c<< endl ;
c |= 2;
cout << "Line 11 - |= Operator, Value of
c = : " <<c<< endl ;
Conditional operator
Operator Example
() ? : a = 2;
b = 9;
c = (a>b) ? 2:7;
Cout<<“c = ”<<c;
Output :
c = 7
Arrays
It is continuous memory of same data
types
Array can be of int , float or char
Syntax :
data_type variable_name[n];
where n is size of array
For example,
int arry[5] ;
Initilization of array
int a[3];
a[0] = 0; a[1] = 1; a[2] = 3;
OR
int a[3] = {0,1,2};
THANK
YOU

More Related Content

PPT
Lecture 3
PPTX
Lecture 2 C++ | Variable Scope, Operators in c++
PPTX
Operators and Expression
PPTX
C operators
PPT
operators and expressions in c++
PPT
Operators in C++
DOCX
Programming Fundamentals lecture 7
PPTX
Operators in C/C++
Lecture 3
Lecture 2 C++ | Variable Scope, Operators in c++
Operators and Expression
C operators
operators and expressions in c++
Operators in C++
Programming Fundamentals lecture 7
Operators in C/C++

What's hot (20)

PPTX
Operators and expressions in C++
PPTX
Few Operator used in c++
PDF
Coper in C
DOCX
18 dec pointers and scope resolution operator
PPTX
Increment and Decrement operators in C++
PPTX
Computer programming 2 Lesson 7
PPT
C++ Overview
PPTX
Operators-computer programming and utilzation
PPTX
Operators and Expressions in Java
PDF
C sharp chap3
DOCX
Basics of c++
PPT
C Prog. - Operators and Expressions
PPT
CBSE Class XI Programming in C++
PPT
Expressions in c++
PPTX
C introduction by thooyavan
PPT
Basic c operators
PDF
cp Module4(1)
PDF
07 ruby operators
PPTX
C++ language basic
PPTX
Operators
Operators and expressions in C++
Few Operator used in c++
Coper in C
18 dec pointers and scope resolution operator
Increment and Decrement operators in C++
Computer programming 2 Lesson 7
C++ Overview
Operators-computer programming and utilzation
Operators and Expressions in Java
C sharp chap3
Basics of c++
C Prog. - Operators and Expressions
CBSE Class XI Programming in C++
Expressions in c++
C introduction by thooyavan
Basic c operators
cp Module4(1)
07 ruby operators
C++ language basic
Operators
Ad

Viewers also liked (20)

PPT
C++ chapter 4
PPTX
C++ Chapter 3
PPTX
C++ Chapter 1
PPTX
Achieving acca approved learning partner (gold status
PDF
CPA Certification Program Review
PPT
ACCA Geography Bee (Grades 4-6)
PDF
Does Your Website Stack Up? CPA Website Findings Revealed
PDF
Ethiopian GTP- Macroeconomic policy and strategy review
PDF
Transitioning from reaching every district to reaching every community
PDF
ACCA Presentation
PPTX
The Economy under President Obama
PDF
Online PMES - Concept of POSSESSION and OWNERSHIP
PPTX
Federal ministry of land, housing & urban development
PDF
Mulu Gebreeyesus: Industrial Policy and Development in Ethiopia: Evolution an...
PPSX
ACCA F9 - exam preparation for Dec 2014
PDF
Urban And Regional Planning And Development Law
PPT
Paul Lydon Notes Acca F9
PPT
Operator & Expression in c++
PPTX
Rural-Urban Transformation in Ethiopia - Implications for Development Strategies
PPTX
Land law [all slides for studentsj]
C++ chapter 4
C++ Chapter 3
C++ Chapter 1
Achieving acca approved learning partner (gold status
CPA Certification Program Review
ACCA Geography Bee (Grades 4-6)
Does Your Website Stack Up? CPA Website Findings Revealed
Ethiopian GTP- Macroeconomic policy and strategy review
Transitioning from reaching every district to reaching every community
ACCA Presentation
The Economy under President Obama
Online PMES - Concept of POSSESSION and OWNERSHIP
Federal ministry of land, housing & urban development
Mulu Gebreeyesus: Industrial Policy and Development in Ethiopia: Evolution an...
ACCA F9 - exam preparation for Dec 2014
Urban And Regional Planning And Development Law
Paul Lydon Notes Acca F9
Operator & Expression in c++
Rural-Urban Transformation in Ethiopia - Implications for Development Strategies
Land law [all slides for studentsj]
Ad

Similar to C++ chapter 2 (20)

PDF
C Operators and Control Structures.pdf
PPTX
C sharp part 001
PPTX
C Operators and Control Structures.pptx
PPTX
C programming(Part 1)
PDF
Programming C Part 02
PPTX
Operators in C++.pptx
PPTX
Operators and it's type
PDF
Constructor and destructors
PPTX
2.overview of c#
PDF
Chap 3 c++
PPS
C programming session 02
PPTX
object oriented programming presentation
PPTX
Operators in c++ programming types of variables
PPTX
Unit 2- Control Structures in C programming.pptx
PDF
C language
PDF
Module 2_PPT_P1 POP Notes module 2 fdfd.pdf
PPTX
11operator in c#
DOCX
Basic commands in C++
C Operators and Control Structures.pdf
C sharp part 001
C Operators and Control Structures.pptx
C programming(Part 1)
Programming C Part 02
Operators in C++.pptx
Operators and it's type
Constructor and destructors
2.overview of c#
Chap 3 c++
C programming session 02
object oriented programming presentation
Operators in c++ programming types of variables
Unit 2- Control Structures in C programming.pptx
C language
Module 2_PPT_P1 POP Notes module 2 fdfd.pdf
11operator in c#
Basic commands in C++

Recently uploaded (20)

PDF
AIGA 012_04 Cleaning of equipment for oxygen service_reformat Jan 12.pdf
PDF
[jvmmeetup] next-gen integration with apache camel and quarkus.pdf
PDF
MLpara ingenieira CIVIL, meca Y AMBIENTAL
PPTX
SE unit 1.pptx aaahshdhajdviwhsiehebeiwheiebeiev
PDF
Cryptography and Network Security-Module-I.pdf
PDF
VSL-Strand-Post-tensioning-Systems-Technical-Catalogue_2019-01.pdf
PDF
VTU IOT LAB MANUAL (BCS701) Computer science and Engineering
PPTX
Solar energy pdf of gitam songa hemant k
PPTX
Environmental studies, Moudle 3-Environmental Pollution.pptx
PDF
Lesson 3 .pdf
PPTX
AI-Reporting for Emerging Technologies(BS Computer Engineering)
PPT
UNIT-I Machine Learning Essentials for 2nd years
PDF
SEH5E Unveiled: Enhancements and Key Takeaways for Certification Success
PPTX
Environmental studies, Moudle 3-Environmental Pollution.pptx
PPTX
Micro1New.ppt.pptx the mai themes of micfrobiology
DOCX
ENVIRONMENTAL PROTECTION AND MANAGEMENT (18CVL756)
PDF
Unit I -OPERATING SYSTEMS_SRM_KATTANKULATHUR.pptx.pdf
PDF
UEFA_Embodied_Carbon_Emissions_Football_Infrastructure.pdf
PPTX
Wireless sensor networks (WSN) SRM unit 2
PPTX
MAD Unit - 3 User Interface and Data Management (Diploma IT)
AIGA 012_04 Cleaning of equipment for oxygen service_reformat Jan 12.pdf
[jvmmeetup] next-gen integration with apache camel and quarkus.pdf
MLpara ingenieira CIVIL, meca Y AMBIENTAL
SE unit 1.pptx aaahshdhajdviwhsiehebeiwheiebeiev
Cryptography and Network Security-Module-I.pdf
VSL-Strand-Post-tensioning-Systems-Technical-Catalogue_2019-01.pdf
VTU IOT LAB MANUAL (BCS701) Computer science and Engineering
Solar energy pdf of gitam songa hemant k
Environmental studies, Moudle 3-Environmental Pollution.pptx
Lesson 3 .pdf
AI-Reporting for Emerging Technologies(BS Computer Engineering)
UNIT-I Machine Learning Essentials for 2nd years
SEH5E Unveiled: Enhancements and Key Takeaways for Certification Success
Environmental studies, Moudle 3-Environmental Pollution.pptx
Micro1New.ppt.pptx the mai themes of micfrobiology
ENVIRONMENTAL PROTECTION AND MANAGEMENT (18CVL756)
Unit I -OPERATING SYSTEMS_SRM_KATTANKULATHUR.pptx.pdf
UEFA_Embodied_Carbon_Emissions_Football_Infrastructure.pdf
Wireless sensor networks (WSN) SRM unit 2
MAD Unit - 3 User Interface and Data Management (Diploma IT)

C++ chapter 2

  • 1. C++ Language By : Shrirang Pinjarkar Email : [email protected]
  • 2. UNIT -2 DATA TYPES , VARIABLES AND OPERATORS
  • 3. Overview Objectives C++ data types, constant and variable C++ keywords Input Output : cin, cout Hands On!
  • 4. DATA TYPE  A data type determines the type of the data that will be stored, usually, in the computer memory (RAM).  Type statements in C++ are used to allow the compiler to:  reserve blocks of memory to store information  give the reserved blocks of memory a symbolic name so that the data contained in this block of memory can be manipulated by referring to this name in future C++ statements.
  • 5. Data Types C++ provides three fundamental data types: - int (integers ) ex: 1 , -8 ,0 ,etc - float (decimal numbers) ex: 2.03 , -7.15 , 0.0 , etc - char (character) ex: ‘a’ , ‘A’ , ‘1’, etc 0 is not float 0.0 is float
  • 6. Name Description Size* Range* char Character 1byte signed: -128 to 127 unsigned: 0 to 255 short int (short) Short Integer. 2bytes signed: -32768 to 32767 unsigned: 0 to 65535 int Integer. 2 or 4 bytes signed: -2147483648 to 2147483647 unsigned: 0 to 4294967295 long int (long) Long integer. 4bytes signed: -2147483648 to 2147483647 unsigned: 0 to 4294967295 bool Boolean value. It can take one of two values: true or false. 1byte true or false float Floating point number. 4bytes +/- 3.4e +/- 38 (~7 digits) double Double precision floating point number. 8bytes +/- 1.7e +/- 308 (~15 digits) long double Long double precision floating point number. 8bytes +/- 1.7e +/- 308 (~15 digits)
  • 7. Exercise  What is the suitable data type for the following?  number of student in your class - unsigned int  your matrix elements - float  assignment marks for this subject - float  the distance to the moon (the distance to the moon is over 200,000 miles) - long double  last month's checking account balance - float /double  a counter used to count the number of lines in a text file - int  number of people living in Malaysia - long  the temperature used in a chemistry formula - float
  • 8. Variables variable  a valid identifier whose value can change during the course of execution of a program general form of the declarations: data-type variable_name; example: int mass; double x, speed, dragForce;
  • 9. Declaration of Variables when a variable is declared, you can initialize it in two alternative but equivalent ways int mass = 22; or int mass; //(garbage value) mass = 22; Declaration of string variable example: string name = “Mohamad”;
  • 10. Variables // Declaration of variables #include <iostream> using namespace std; int main () { short x = 22, y = 11, z; z = x - y; cout << "z = " << z << endl; int p = 3; int q = x * y * z - 2 * p; cout << "q = " << q << endl; return 0; }
  • 11. Exercise : Correct the following errors  long Float x; long x;  int code = three, int code = 3;  const int array size; const int array_size; Declare the following variable: Name Type Initial value marks double None grade char A price float 10.0 num_1 int 5 msg string Hello World result bool true
  • 12. Scope of Variable variable can have either local or global scope scope (visibility) of local variables is limited to the block enclosed in braces ({ }) where they are declared global variables are declared outside of all blocks and their scope are the entire program, i.e. the main body of the source code.
  • 13. What is the Scope of A variable ? Scope refers to the visibility of variables. In otherwords, which parts of your program can see or use it. Normally, every variable has a global scope. Once defined, every part of your program can access a variable.
  • 14. A scope is a region of the program and broadly speaking there are three places, where variables can be declared: Inside a function or a block which is called local variables, In the definition of function parameters which is called formal parameters. Outside of all functions which is called global variables.
  • 15. Operators in C++ An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. C++ is rich in built-in operators and provides the following types of operators: Arithmetic Operators Relational Operators Logical Operators Bitwise Operators Assignment Operators
  • 16. Arithmetic Operators: Assume variable A holds 10 and variable B holds 20 Operat or Description Result + Adds two operands 30 - Subtracts second operand from first -10 * Multiplies both Operands 200 / Divides numerator by De-numerator B/A=2 % Modulus Operator and reminder of after integer division A%B=0 ++ Increment operator , increases integer value by one 11 A++ -- Decrement Operator, Decreases Integer Value by One 9
  • 17. 7/8/2014 By Himanshu Kaushik | ApplicationDeveloper.in | Himanshukaushik.in main() { int a = 21; int b = 10; int c ; c = a + b; cout << "Line 1 - Value of c is :" << c << endl ; c = a - b; cout << "Line 2 - Value of c is :" << c << endl ; c = a * b; cout << "Line 3 - Value of c is :" << c << endl ; c = a / b; cout << "Line 4 - Value of c is :" << c << endl ; c = a % b; cout << "Line 5 - Value of c is :" << c << endl ; c = a++; cout << "Line 6 - Value of c is :" << c << endl ; c = a--; cout << "Line 7 - Value of c is :" << c << endl ; return 0;
  • 18. Relational Operators Assume variable A holds 10 and variable holds 20 Operato r Description Example == Checks if the Value of two Operands are Equal or not , if yes then condition becomes True (A==B) is not true != Checks if the value of two operands are equal or not , if values are not equal then condition becomes true (A!=B) is true > Checks if the value of Left operand is greater than the value of right operand , if yes then condition becomes true, (A>B) is not true < , >= , <= are relationals operators
  • 19. Bitwise Operators Bitwise operator works on bits and perform bit-by-bit operation. P Q P & Q P|Q P^Q 0 0 0 0 0 0 1 0 1 1 1 1 1 1 0 1 0 0 1 1
  • 20. if A = 60; and B = 13 Assume if A = 60; and B = 13; now in binary format they will be as follows:  A = 0011 1100  B = 0000 1101  A&B = 0000 1100  A|B = 0011 1101  A^B = 0011 0001  ~A  = 1100 0011
  • 21. Operato r Description Result & Binary AND Operator copies a bit to the result if it exists in both operands. (A & B) will give 12 which is 0000 1100 | Binary OR Operator copies a bit if it exists in either operand. (A | B) will give 61 which is 0011 1101 ^ Binary XOR Operator copies the bit if it is set in one operand but not both. (A ^ B) will give 49 which is 0011 0001
  • 22. Operato r Description Result ~ Binary Ones Complement Operator is unary and has the effect of 'flipping' bits. (~A ) will give -61 which is 1100 0011 in 2's complement form due to a signed binary number. << Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand. A << 2 will give 240 which is 1111 0000 >> Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand. A >> 2 will give 15 which is 0000 1111
  • 23. By Himanshu Kaushik | ApplicationDeveloper.in | Himanshukaushik.in main() { unsigned int a = 60; // 60 = 0011 1100 unsigned int b = 13; // 13 = 0000 1101 int c = 0; c = a & b; // 12 = 0000 1100 cout << "Line 1 - Value of c is : " << c << endl ; c = a | b; // 61 = 0011 1101 cout << "Line 2 - Value of c is: " << c << endl ; c = a ^ b; // 49 = 0011 0001 cout << "Line 3 - Value of c is: " << c << endl ; c = ~a; // -61 = 1100 0011 cout << "Line 4 - Value of c is: " << c << endl ; c = a << 2; // 240 = 1111 0000 cout << "Line 5 - Value of c is: " << c << endl ; c = a >> 2; // 15 = 0000 1111 cout << "Line 6 - Value of c is: " << c << endl ;
  • 24. Assignment Operators By Himanshu Kaushik | ApplicationDeveloper.in | Himanshukaushik.in Operator Description Example = Simple assignment operator, Assigns values from right side operands to left side operand C = A + B will assign value of A + B into C += Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand C += A is equivalent to C = C + A -= Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand C -= A is equivalent to C = C - A
  • 25. Assignment Operators Operator Description Example *= Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand C *= A is equivalent to C = C * A /= Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand C /= A is equivalent to C = C / A %= Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand C %= A is equivalent to C = C % A
  • 26. 7/8/2014 By Himanshu Kaushik | ApplicationDeveloper.in | Himanshukaushik.in main() { int a = 21; int c ; c = a; cout << "Line 1 - = Operator, Value of c = : " <<c<< endl ; c += a; cout << "Line 2 - += Operator, Value of c = : " <<c<< endl ; c -= a; cout << "Line 3 - -= Operator, Value of c = : " <<c<< endl ; c *= a; cout << "Line 4 - *= Operator, Value of c = : " <<c<< endl ; c /= a; cout << "Line 5 - /= Operator, Value of c = : " <<c<< endl ; c = 200; c %= a; cout << "Line 6 - %= Operator, Value of c = : " <<c<< endl ; c <<= 2; cout << "Line 7 - <<= Operator, Value of c = : " <<c<< endl ; c >>= 2; cout << "Line 8 - >>= Operator, Value of c = : " <<c<< endl ; c &= 2; cout << "Line 9 - &= Operator, Value of c = : " <<c<< endl ; c ^= 2; cout << "Line 10 - ^= Operator, Value of c = : " <<c<< endl ; c |= 2; cout << "Line 11 - |= Operator, Value of c = : " <<c<< endl ;
  • 27. Conditional operator Operator Example () ? : a = 2; b = 9; c = (a>b) ? 2:7; Cout<<“c = ”<<c; Output : c = 7
  • 28. Arrays It is continuous memory of same data types Array can be of int , float or char Syntax : data_type variable_name[n]; where n is size of array For example, int arry[5] ;
  • 29. Initilization of array int a[3]; a[0] = 0; a[1] = 1; a[2] = 3; OR int a[3] = {0,1,2};

Editor's Notes

  • #6: wchar_t: for special character eg: symbol/international language wchar_t myChar1 = L&amp;apos;Ω&amp;apos;; wchar_t myString1[] = L&amp;quot;♠♣♥♦&amp;quot;;