Upload
ghe-patani
View
44
Download
0
Embed Size (px)
Citation preview
5/13/2018 cpp quiz - slidepdf.com
http://slidepdf.com/reader/full/cpp-quiz 1/3
1. What function initalizes variables in a class:
ConstructorDestructorConstitutorA and B are correct.
2. To include code from the library in the program, such as iostream, a directive would be called up using this command.
#include <>; with iostream.h inside the bracketsinclude (iostreamh)#include <> with iostream.h inside the bracketsinclude #iostream,h;
3. Single line comments explaining code would be preceded like in the followingexample
/**
//*///*
4. Which line has all reserved words ?
char, int, float, doubled, short, long, unsigned, signedsizeof, const, typedef, static, voided, enum, struct, unionif, else, for, while do, switch, continue, breakdefaulted, goto, return, extern, private, public, protected
5. What punctuation must each command line have at the end of the line ?
:,!;
6. The C++ language is
case-sensitive.Not case-sensitive.It dependsNone of these
7. The number 5.9875e17 must be stored in a(n):
intlongdoublefloat
8. Select the correct definition for a string variable.
string mystr;string mystr[20];string[20] mystr;char mystr[20];
9. The sentence "Hello world!" uses _____ elements in a character array.
5/13/2018 cpp quiz - slidepdf.com
http://slidepdf.com/reader/full/cpp-quiz 2/3
10111213
10. When you are creating a structure, you need to use the following keyword
structurestructobjectrecord
11. Select the correct function definition (NOT prototype) from the list below.
void intro();double sin(double rad);int foo(int bar; double baz)double pow(double num, int pow);
12. Cout can print multiple values or variables in a single command using the following syntax:
cout << "Hi" + bob + "\n";cout << "Hi" << bob << "\n";cout << "Hi", bob, "\n";cout << ("Hi" & bob & "\n");
13. Write a for loop that counts from 0 to 5.
for (c = 0; c <= 5; c++)for (int c = 0; c <= 6; c++)for (c = 0; c < 5; c++)
for (c = 0; c < 5; c++);
14. What does the statement #include do ?
It defines the function iostream.hIt tells the compiler where the program beginsIt defines the words TRUE and FALSEIt allows the programmer to use cout << It defines the statement return
15. Which of the following converts an integer "value" to its ASCII equivalent ?
atoi(value)
cout << value(char) valuechar (value)
16. Indicate which data type is not part of standard C++.
boolintrealdouble
17. Which one of the choices would produce the following output ?
cout << "Hello" << "World";cout << "Hello \n World";cout << "Hello World\n";
5/13/2018 cpp quiz - slidepdf.com
http://slidepdf.com/reader/full/cpp-quiz 3/3
cin >> "Hello World";
18. What is the output of the following code?for (int i=0; i<10; i++); cout << i%2 << " "; }
0 1 2 3 4 5 6 7 8 90 2 4 6 8 10 12 14 16 18
1 0 1 0 1 0 1 0 1 00 1 0 1 0 1 0 1 0 1
19. What is the output of the following code?for (int a = 1; a <= 1; a++) cout << a++; cout << a;
2212error23
20. For which values of the integer _value will the following code become an inf
inite loop?int number=1;while (true) {cout << number;if (number == 3) break;number += _value; }
only 0only 1only 2only 1 or 2