Test
Programming Chapter 1-4 Test
Este test tiene tiempo límite, así que se abre en el reproductor de siempre.
Preguntas del test (30)
1Which of the following is the correct way to declare comments?
- A//
- B#
- C/*?
- D/*.
2Which preprocessor directive is needed to perform the cout/cin commands in C++ (assume we are using namespace std)
- A#include <stddlib.h>
- B#include <stdio.h>
- C#include <iostream>
- D#include <namespace>
3Why are semicolons used in C++ and more modern version of C?
- ASemicolons make code cleaner
- BSemicolons are used to mark the beginning and end of a function, similar to python
- CSemicolons are only needed in Object oriented programming
- DSemicolons are used to mark the end a command
4Which of the following are valid ways to declare a variable in C++? (this is a MULTIPLE answered question, select all that apply)
- Aint x = 5;
- Bint y = 3, 4;
- Cint[] x = {3, 3};
- Dint x, y = 3;
- Eint z = 4
5Which of the following is a valid way to get the total size of a datatype integer?
- Aint size = sizeof(char);
- Bint size = size(int);
- Cint size = sizeof(int);
- Dint size = sizeof(std::uint16_);
6Whats wrong with this program?
int Main(int argc, char* argv[])
{
return 0;
}- AReturn 0 must have an indent
- BThe parameters passed are invalid
- CThe main function cannot be capitalized
- DAll of the above are correct
7Which of the following is the right way to declare a character?
- Achar 12char = 'A';
- Bchar char12 = ' ';
- Cchar char12 = "A";
- Dchar 12char = "5";
8Whats wrong with this function?
void getArea(int w, int h){
return w * h;
}- AA. The curly bracket has to be declared on a seperate line
- BB. Returned values are not allowed for a return type 'void'
- CC. getArea() has to return an integer
- DD. A and C are correct
- EE. B and C are correct
- FF. A, B, and C are correct
9What is a double data type short for?
- ADouble precision of a 4 byte integer
- BDouble data
- CDouble precision of a floating point type
- DDouble is not a short form for anything
10Which of the following is not a built in data type?
- Aint
- Bunion
- Cwide character
- Dvoid
11Which of the following is a user defined data type?
- Aarray
- Bfunction pointer
- Cinteger pointer
- Dstruct
12Which operator is used to get the remainder of a division?
- A%
- B/
- C?
- DR
13What will this program print on screen?
#include <iostream>
int main()
{
int num1 = 40;
int num2 = 10;
int num3 = num1 / num2;
int num4 = (num3 + 1) % 4;
std::cout << num4 << std::endl;
return 0;
}- Acompiler error
- B1
- C2
- D3
- E4
- F5
14Which of the following is not true about if statements?
- AAn if statement will execute a block of code in curly brackets if the condition is true
- BAn if statement does not need curly brackets for only one command that should be executed if the condition comes to true
- CAn if statement will skip the code inside a body if the condition is false
- DAll of the above are correct
- EAll of the above are incorrect
15What will this program output?
#include <iostream>
using namespace std;
int main()
{
int a = 4;
int b = 3;
const int c = a * b;
if (a < b)
{
cout << "Were here" << endl;
}
else if (a * 3 == c)
{
cout << "Were over here" << endl;
}
else if (false)
{
cout << "Were over here instead" << endl;
}
else
{
cout << "Were getting nowhere" << endl;
}
return 0;
}- AWere over here
- BWere here
- CWere over here instead
- DWere getting nowhere
- ECompile error
16What will the following program output?
#include <iostream>
using namespace std;
int getArea(int width, int height, int depth)
{
return width * height * depth;
}
int main()
{
cout << getArea(2, 2, 2) - 4 << endl;
return 0;
}- A4
- B8
- C12
- D16
17What will the following program output?
#include <iostream>
using namespace std;
int main()
{
int num=90;
if( num < 100 )
{
cout<<"number is less than 100"<<endl;
if(num > 50)
{
cout<<"number is greater than 50";
}
}
return 0;
}- Anumber is greater than 100
number is less than 50 - Bnumber is less than 100
number is greater than 50 - Cnumber is less than 50
- DCompile error
- ENone of the above
- Anumber is greater than 100
18True or false: The code written in Question 17 is called object code
- AVerdadero
- BFalso
19How many bytes does a float take up in memory?
- A1
- B2
- C4
- D8
- E16
20How many bytes are in 24 bits?
- A3
- B4
- C1
- D2
21Which of the following is an example of an input device?
- Aspeaker
- Bmonitor
- Cmouse
- Dheadphones
22How many bytes are stored in a character?
- A1
- B2
- C4
- D8
23Which of the following is not a valid expression for declaring a boolean variable?
- Abool flag = false;
- Bbool flag = 2;
- Cbool flag = true;
- Dbool flag = 1;
- E#define EXPR true
bool flag = EXPR;
24What will the following program output?
#include <iostream>
using namespace std;
int main(){
char ch='b';
switch(ch) {
case 'd': cout<<"Case1 ";
break;
case 'b': cout<<"Case2 ";
break;
case 'x': cout<<"Case3 ";
break;
case 'y': cout<<"Case4 ";
break;
default: cout<<"Default ";
}
return 0;
}- ACompile error
- BCase 2
- CCase 1
- DCase 4
- ECase 5
- FDefault
25We use the expression system("pause") to pause the console
- AVerdadero
- BFalso
26What is the equivalent of the following expression?
int x = 5;
Expression: -> x += 1; <-- Ax++;
- Bx+++;
- Cx+;
- DC++
- Ex--
27Whats wrong with the following program?
int main()
{
int arr[] = { 1, 2, 3 }
}- ANo semicolon
- BForgot to include <iostream>
- CForgot to write using namespace std;
- DNothing is wrong here
28True or false: We use std::endl to end the line on the console
- AVerdadero
- BFalso
29Which of the following is an example of object code?
- A0xfff
- B01011011
- Creturn 0;
- DNone of the above
30What is the equivalent of this statement?
0xff- A255
- B2.147 billion
- C4095
- D65535
Información
- Descripción
- Grade 12 Introduction to Programming Test sobre Programming Chapter 1-4 Test, creado por Liam Blake el 07/10/2021.
- Autor
- Liam Blake
- Idioma
- English
- Visitas
- 0
- Etiquetas
- Valoración
- Aún sin valoraciones Valora este test
Más sobre C++ Programming Basics