Object Oriented Programming3
Object Oriented Programming3
#include <iostream.h>
int main()
// variable declaration
int number;
return 0;
#include <iostream.h>
#include<conio.h>
int main()
clrscr();
// Prints sum
cout << firstNumber << " + " << secondNumber << " = " << sumOfTwoNumbers;
getch();
return 0;
#include <iostream.h>
int main()
return 0;
}
#include <iostream.h>
int main()
cout << "a = " << a << ", b = " << b << endl;
temp = a;
a = b;
b = temp;
cout << "a = " << a << ", b = " << b << endl;
return 0;
Before swapping.
a = 5, b = 10
After swapping.
a = 10, b = 5
Data Types
Data types define the type of data a variable can hold, for example an integer
variable can hold integer data, a character type variable can hold character data
etc. Data types in C++ are categorised in three groups: Built-in, user-defined
and Derived.
The data type specifies the size and type of information the variable will store:
In the example below, we use the + operator to add together two values:
Example
1. Arithmetic operators
2. Assignment operators
3. Comparison operators
4. Logical operators
5. Bitwise operators
Arithmetic Operators
= x=5 x=5
+= x += 3 x=x+3
-= x -= 3 x=x-3
*= x *= 3 x=x*3
/= x /= 3 x=x/3
%= x %= 3 x=x%3
|= x |= 3 x=x|3
^= x ^= 3 x=x^3
Comparison Operators
Note: The return value of a comparison is either true (1) or false (0).
In the following example, we use the greater than operator (>) to find out if 5 is
greater than 3:
Example
== Equal to x == y
!= Not equal x != y
Logical Operators
Logical operators are used to determine the logic between variables or values:
If x = 2
&& Logical and Returns true if both statements are true (x < 5 && x <
10)
|| Logical or Returns true if one of the statements is true
x < 5 || x < 4
#include<iostream.h>
void main()
int x = 0;
#include<iostream.h>
void main()
int x = 0;