Variables, Data Types, Constants and Operators
What is wrong with this program?
main() { p=47; cout << p; }
What is wrong with this declaration?
int x = y = 95;
Write four different C++ statements that subtract 1 from the integer variable
x
.
Which of the following are valid C++ statements? Evaluate the ones which are valid.
x = 65/5*2
65 / 4 = k;
p = 65(4*7);
x = 34 - 4 * 7;
x = 34 - ( 4 * 7);
54 % 5 = h ;
x = 54 % 7;
Answers
The
#include <iostream.h>
is missing and the variable
p
has not been declared.
The equals sign can only be used in a declaration to initialise a variable. Therefore it should be
int x=95, y =95;
x = x - 1; x --; --x; x -= 1;
missing ;
not valid - should be
k = 64/4;
not valid
valid x = 6
valid
not valid
valid x = 5
Back to Questions
Back to Main Page for Lecture 2