NEW
Font size
WorksheetsC++ Worksheet
Total questions: 40
Worksheet time: 20mins
Which data type do we use to store a single letter?
int
char
float
string
Which command prints the text "Hello" on the screen?
cout << "Hello";
cin >> "Hello";
print("Hello");
echo "Hello";
Which command inputs an integer into the variable x?
cin >> x;
cout << x;
input(x);
scanf("%d", x);
Which data type do we use for whole numbers?
int
float
char
string
Which data type do we use for decimal numbers?
int
float
char
bool
Which command adds 1 to the variable x?
x = x + 1;
x = x - 1;
x * 1;
x / 1;
Which command prints the string s?
cout << s;
cin >> s;
print(s);
printf(s);
Which command checks whether x equals 5?
if(x == 5)
if(x = 5)
if(x === 5)
if x = 5
Which statement executes a block of code at least once and repeats while the condition is true?
do-while
for
while
repeat
Which command adds the values a and b and stores the result in c?
c = a + b;
c = a - b;
c = a * b;
c = a / b;
Which command increases the value of x by 5?
x = x + 5;
x = x - 5;
x * 5;
x / 5;
Which command correctly prints the number stored in variable x?
cout << x;
cin >> x;
print(x);
printf(x);
Which command inputs a number from the keyboard into the variable x?
cin >> x;
cout >> x;
input(x);
scanf(x);
Which command prints the value of x inside a loop?
cout << x;
cin >> x;
print(x);
printf(x);
Which operator adds two values a and b?
-
*
+
/
Which command checks whether x is greater than 0?
if(x > 0)
if(x < 0)
if(x == 0)
if(x >= 0)
Which loop runs while the condition is true?
for
while
do-while
repeat
How do you assign the value 10 to variable x?
x = 10;
x := 10;
x <= 10;
x == 10;
Which command prints "Welcome" if x is greater than 5?
if(x > 5) cout << "Welcome";
if(x > 5) cin >> "Welcome";
if(x > 5) print("Welcome");
if(x > 5) echo "Welcome";
Which command prints "Even" if the number x is even?
if(x % 2 == 0) cout << "Even";
if(x % 2 = 0) cout << "Even";
if(x / 2 == 0) cout << "Even";
if(x * 2 == 0) cout << "Even";
Which loop prints the numbers from 1 to 5?
for(int i=1; i<=5; i++) cout << i;
for(int i=0; i<5; i++) cout << i;
while(i<=5) cout << i;
do cout << i; while(i<=5);
Which data type uses logical values (true/false)?
int
float
bool
char
Which command decreases the value of x by 1?
x++
x--
x = x + 1
x = x * 1
Which command checks whether x is less than or equal to 10?
if(x <= 10)
if(x < 10)
if(x == 10)
if(x => 10)
Which operator subtracts the values a and b?
+
-
*
/
Which statement repeats a block of code exactly 10 times?
for(int i=0; i<10; i++)
while(i<10)
do-while
repeat 10
Which command checks whether x is NOT equal to 5?
if(x != 5)
if(x =! 5)
if(x < 5)
if(x != 5;)
Which command prints a value n times?
a) for(int i=0;i<n;i++) cout << n;
if(n>0) cout << n;
while(n) cin >> n;
do cout << n; while(n);
Which command checks whether x is greater than 0 and less than 10?
if(x > 0 && x < 10)
if(x > 0 || x < 10)
if(x > 0 & x < 10)
if(x >= 0 && x <= 10)
Which command checks whether x is greater than 5 or y equals 10?
if(x > 5 && y == 10)
if(x > 5 || y == 10)
if(x > 5 | y == 10)
if(x > 5 and y == 10)
Which input command uses multiple values at once?
cin >> a >> b;
cin << a << b;
cin(a, b);
input(a, b);
Which operator returns the remainder in division?
/
%
*
//
Which command prints the values from 1 to 10 using a while loop?
int i = 1; while(i <= 10){ cout << i; i++; }
for(i = 1; i <= 10; i++) cout << i;
do cout << i; while(i <= 10);
while(i < 10) cout << i;
Which command checks whether x is greater than 0 and less than 5 or y equals 10?
if((x > 0 && x < 5) || y == 10)
if(x > 0 && x < 5 || y == 10)
if(x > 0 & x < 5 | y == 10)
if(x > 0 || x < 5 && y == 10)
Which command decreases the value of x by 5?
x = x - 5;
x = x + 5;
x--5;
x = 1;
Which command checks if the number x is even and greater than 0?
if(x % 2 == 0 && x > 0)
if(x % 2 = 0 && x > 0)
if(x % 2 == 0 || x > 0)
if(x / 2 == 0 && x > 0)
Which output command uses a new line after the text?
cout << "Hello" << endl;
cout >> "Hello" << endl;
cout << "Hello";
cout << Hello;
Which command checks if x is greater than 10 and less than 20?
if(x > 10 && x < 20)
if(x > 10 || x < 20)
if(x > 10 && x <= 20)
if(x = 10 && x = 20)
Which operator multiplies two values a and b?
+
-
*
/
Which command assigns the value 100 to the variable y?
y == 100;
y = 100;
y := 100;
y <= 100;
