3 2
3 2
varChar
− Is a char variable
− Is the argument (parameter) of the function
char ch1, ch2; What is stored in ch1,
int num; ch2 and num if the input
is:
cin >> ch1 >> ch2 >> num;
A 25
void main()
{
cout << "-2 + 5 = " << -2 + 5 << endl;
cout << "10 - 20 = " << 10 - 20 << endl;
cout << "2 * 7 = " << 2 * 7 << endl;
cout << "5 / 2 = " << 5 / 2 << endl;
cout << "5.0 / 2 = " << 5.0 / 2 << endl;
cout << "5 / 2.0 = " << 5 / 2.0 << endl;
cout << "34 % 5 = " << 34 % 5 << endl;
cout << "4 % 6 = " << 4 % 6 << endl;
getch();
}
Relational Operators
• Mixed expression:
− Has operands of different data types
− Contains integers and floating-point
• Examples of mixed expressions:
2 + 3.5
6 / 4 + 3.9
5.4 * 2 – 13.6 + 18 / 2
Mixed Expressions (continued)
• Evaluation rules:
− If operator has same types of operands
• Evaluated according to the type of the operands
− If operator has both types of operands
• Integer is changed to floating-point
• Operator is evaluated
• Result is floating-point
− Entire expression is evaluated according to
precedence rules
What is the output?
#include <iostream>
#include<conio.h>
using namespace std;
void main()
{
cout << "3 / 2 + 5.5 = " << 3 / 2 + 5.5 << endl;
cout << "10.6 / 2 + 5 = " << 10.6 / 2 + 5 <<
endl;
cout << "4 + 5 / 2.0 = " << 4 + 5 / 2.0 << endl;
cout << "4 * 3 + 7 / 5 - 12.5 = "
<< 4 * 3 + 7 / 5 - 12.5
<< endl;
getch();
}