DR M. Arifur Rahman: PHY-206 Cpna
DR M. Arifur Rahman: PHY-206 Cpna
CPNA
Dr M. Arifur Rahman
Associate Professor
Content
#include <iostream>
int main()
{
double x, y;
cout << "\nEnter two floating-point values: ";
In its simplest form, an expression consists of only one constant, one variable, or one
function call. Expressions can be used as the operands of operators to form more
complex expressions. An expression will generally tend to be a combination of operators
and operands.
Each expression that is not a void type returns a value. In the case of arithmetic
expressions, the operands define the type of the expression.
Examples:
int a(4);
double x(7.9);
a * 512 // Type int
1.0 + sin(x) // Type double
x – 3 // Type double, since one
Given that i is a variable, both i++ (postfix notation) and ++i (prefix notation) raise the
value of i by 1. In both cases the operation i = i + 1 is performed.
However, prefix ++ and postfix ++ are two different operators. The difference becomes
apparent when you look at the value of the expression; ++i means that the value of i has
already been incremented by 1, whereas the expression i++ retains the original value of
i. This is an important difference if ++i or i++ forms part of a more complex expression:
The decrement operator -- modifies the operand by reducing the value of the operand
by 1. As the sample program opposite shows, prefix or postfix notation can be used with
--
#include <iostream>
int main()
{
int i(2), j(8);
cout << i++ << endl; // Output: 2
cout << i << endl; // Output: 3
cout << j-- << endl; // Output: 8
cout << --j << endl; // Output: 6
return 0;
}