Page 29 - DCAP404 _Object Oriented Programming
P. 29
Object-oriented Programming
Notes
Example:
#include <iostream>
using namespace std;
int main ()
{
int a, b; // a:?, b:?
a = 10; // a:10, b:?
b = 4; // a:10, b:4
a = b; // a:4, b:4
b = 7; // a:4, b:7
cout << “a:”;
cout << a;
cout << “ b:”;
cout << b;
return 0;
}
Self Assessment
Fill in the blanks:
3. Assignment expression assigns the value of an expression, a constant or a variable to
an……………….. .
2.3 Operators
An expression is a combination of variables, constants and operators written according to some
rules. An expression evaluates to a value that can be assigned to variables and can also be used
wherever that value can be used.
Individual constant, variables, array elements function references can be joined together by
various operators to form expressions. C++ includes a large number of operators, which fall
into several different categories. In this section we examine some of these categories in detail.
Specifically, we will see how arithmetic operators; unary operators, relational and logical
operators, assignment operators and the conditional operator are used to form expressions.
The data items that operators act upon are called operands. Some operators require two operands,
while others act upon only one operand. Most operators allow the individual operands to be
expressions. A few operators permit only single variables as operands.
Operators are used to compute and compare values, and test multiple conditions. They can be
classified as:
1. Arithmetic operators
2. Assignment operators
22 LOVELY PROFESSIONAL UNIVERSITY