Lecture 4 CPP
Lecture 4 CPP
using C++
Mr.B. Srinu
Contents
Structure of a C++ Program
Data Types
Operators
Strcuture of C++ Program
Preprocessor Directives
Class definition
void Circle::display()
{
area = PI * r*r;
cout<< "Area of circle is " <<area;
}
int main ( )
{
Circle c1;
c1.read();
c1.display();
return 0;
}
Datatypes
Primitive Data Type Categories:
Integer
Character
Floating point numbers
Boolean
void
Datatype modifiers:
signed / unsigned
short / long
Datatypes
DATA TYPE SIZE (IN BYTES) RANGE
Syntax:
type variable_list;
Example:
int i,j,l;
short int si;
unsigned int ui;
double balance, profit, loss;
Operators
Type of Operation to be carried out
Types
Unary , Binary , Ternary
Operators in C++ are:
Arithmetic Operators
Relational Operators
Bit-wise Operators
Conditional operator (?)
Assignment Operator
& , * operators
Arithmetic Operators
z= x || y => true
z= !x => false
Bitwise Operators
c=a&b =>0
c=a|b =>6
c=a^b =>6
c=~a =>-3
c=a<<1 =>4
c=a>>1 => 1
Conditional Operators
Ternary Operator
int x = 10;
variable_name = expression;
sizeof operator:
double f;
sizeof f => 8
sizeof(int)) => 4
Structure of C++ Program
Data Types
Operators