Lec 6 PF
Lec 6 PF
Lecture 6
Few Terminologies
cin (pronounced see-in) stands for console input.
The >> symbol, referred to as the stream extraction
operator, assigns an input to a variable.
The user then enters number, which is assigned to variable
radius.
cin object causes a program to wait until data is entered at
the keyboard and the Enter key is pressed.
Comments
#include <iostream>
using namespace std;
int main()
{
int i = 4;
int j = 0;
cout<< i / j << endl;
return 0;
}
Logic Errors
(3 + 4 * x) / 5 – (10 * (y - 5) * (a + b + c) )/ x + (9 *
(4 / x + (9 + x) / y))
Precedence of Operators
Highest: ()
Next: *,/,%
Lowest: +,-
Expression Evolution
int i = j = k = 1;
Augmented Assignment Operators /
Compound assignment Operators
Example
x /= 4 + 5.5 * 1.5;
is same as
x = x / (4 + 5.5 * 1.5);
What will be the output?
int a = 6;
a -= a + 1;
cout << a << endl;
a *= 6; cout << a << endl;
a /= 2; cout << a << endl;
Show the output of the following code:
#include <iostream>
using namespace std;
int main() { cout << "3.5 * 4 / 2 – 2.5 = " << (3.5 * 4 / 2 – 2.5)
<< endl;
return 0; }
Show the output of the following code:
#include <iostream>
using namespace std;
int main() { cout << "C++" << "Java" << endl; cout << "C+
+" << endl << "Java" << endl; cout << "C++, " << "Java, " <<
"and C#" << endl;
return 0; }
Show the printout of the following code:
int a = 6;
a -= a + 1;
cout << a << endl;
a *= 6; cout << a << endl;
a /= 2; cout << a << endl