0% found this document useful (0 votes)
296 views9 pages

Cplusplus

The document contains 50 multiple choice questions about C++ programming concepts such as data types, operators, functions, arrays, pointers, classes, inheritance and more. It covers topics like variable scope and initialization, arithmetic operators, conditional statements, loops, functions, strings, structures, unions, file I/O and more. The questions test understanding of fundamental C++ programming concepts.

Uploaded by

dpb4u
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
0% found this document useful (0 votes)
296 views9 pages

Cplusplus

The document contains 50 multiple choice questions about C++ programming concepts such as data types, operators, functions, arrays, pointers, classes, inheritance and more. It covers topics like variable scope and initialization, arithmetic operators, conditional statements, loops, functions, strings, structures, unions, file I/O and more. The questions test understanding of fundamental C++ programming concepts.

Uploaded by

dpb4u
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 9

1.

When working with character arrays, always reserve enough array elements to
hold the string AND its null-terminating character (\0).
[a] True
[b] False
2. In C++, 14 % 4 =
[a] 1
[b] 2
[c] 3
[d] 4
3. Variables that are declared, but not initialized, contain
[a] blank spaces
[b] zeros
[c] "garbage" values
[d] nothing - they are empty
4. Array indexing always starts with the number
[a] 0
[b] 1
[c] 2
[d] \0
5. A character variable may contain up to seven letters.
[a] True
[b] False
6. All strings end with a null zero in memory.
[a] True
[b] False
7. In C++. 5 / 2 =
[a] 2
[b] 2.5
[c] 3
[d] none of the above
8. Variables with names that describe the data stored at that particular memory
location are called
[a] identifiers
[b] constant variables
[c] floating point variables
[d] mnemonic variables
9. The name of a variable is known as its
[a] identifier
[b] constant
[c] data type
[d] base
10. The special class developed by the College Board to be used with strings is
[a] apstrings.cpp
[b] apstring.cpp
[c] aparray.cpp
[d] apletters.cpp
11. In C++, the % refers to
[a] percentages
[b] modulus operator
[c] division
[d] data storage
12. A variable is given a value through
[a] osmosis
[b] the cout statement
[c] the <iomanip.h> header file
[d] an assignment statement
13. Variable names may begin with a number.
[a] True
[b] False
14. When a data type must contain decimal numbers, assign the type
[a] int
[b] char
[c] double
[d] long int
15. Mathematicians and computers interpret the equal sign (=) in the same way.
[a] True
[b] False
16. setprecision requires the header file
[a] stdlib.h
[b] iomanip.h
[c] console.h
[d] conio.h
17. The following statement is valid. double price = 7,450.98;
[a] True
[b] False
18. All variables must be declared before they can be used.
[a] True
[b] False
19. Character literals always have a length of one.
[a] True
[b] False
20. If char catname[15]; , which of the following is valid?
[a] catname[15] = "Millie";
[b] catname = "Millie";
[c] catname[ ] = "Millie";
[d] none are valid

Question #1
What number of digits that can be accurately stored in a float (based on the IE
EE Standard 754)?
6
38
An unlimited number
Question #2
Which of the following is evaluated first:
&&
||
!

Question #3
What does 7/9*9 equal (in C and C++)?
1
0.08642
0
Question #4
Which is not valid in C?
class aClass{public:int x;};
/* A comment */
char x=12;
Question #5
Which of the following is not a valid declaration for main()?
int main()
int main(int argc, char *argv[])
They both work
Question #6
Evaluate the following as true or false: !(1 &&0 || !1)
True
False
Invalid statement
Question #7
Which command properly allocates memory?
char *a=new char[20];
char a=new char[20];
char a=new char(20.0);
Question #8
What operator is used to access a struct through a pointer?
->
>>
*
Question #9
Which is not an ANSI C++ function?
sin()
kbhit()
tmpnam()
Question #10
True or false: If you continuously increment a variable, it will become negativ
e?
True
False
It depends on the variable type
Question #11
What character terminates all strings composed of character arrays?
\0
.
\END
Question #12
If you push 1, 3, and 5 - in that order - onto a stack, which number is popped
out first?
5
1
3
Question #13
What does the code strcat(an_array, "This"); do?
Copies "This" into an_array
Adds "This" to the end of an_array
Compares an_array and "This"
Question #14
Evaluate the following:
int fn(int v)
{
if(v==1 || v==0)
return 1;
if(v%2==0)
return fn(v/2)+2;
else
return fn(v-1)+3;
}
for fn(7);
10
11
1
Question #15
Evaulate the following: 22%5
2
4
0
Question #16
Which of the following data structures is on average the fastest for retrieving
data:
Binary Tree
Hash Table
Stack
Question #17
What is the output of the following code:
int v()
{
int m=0;
return m++;
}
int main()
{
cout<<v();
}
1
0
Code cannot compile
Question #18
Which of the following functions initalizes the variables contained in a class:
Constructor
Destructor
Constitutor
Question #19
Is C++ case sensitive?
No
Case sensitivity is compiler-determined
Yes
Question #20
Which datatype can store decimal numbers?
unsigned int
char
float
Question #21
What does the code "cout<<(0==0);" print?
0
1
Compiler error: Lvalue required
Question #22
According to the ANSI C++ standard, what does the getch() do?
Reads in a character
Checks the keyboard buffer
Nothing (getch() is not an ANSI C++ function)
Question #23
If the program completes executing successfully, what value should the function
main() return?
0
1
void
Question #24
C is to C++ as 1 is to
What the heck?
2
10
Question #25
Which of the following sorts is quickest when sorting the following set: 1 2 3
5 4
Quick Sort
Bubble Sort
Merge Sort
Question #26
What is the outcome of running the following code: int c=0; cout<<c++<<c;
Undefined
01
00
Question #27
What is the maximum value of an unsigned char?
255
256
128
Question #28
In the following declaration of main, "int main(int argc, char *argv[])", to wh
at does argv[0] usually correspond?
The first argument passed into the program
The program name
You can't define main like that
Question #29
In which header file is isalpha() declared?
conio.h
stdio.h
ctype.h
Question #30
What will happen when the following code is run:
int x;
while(x<100)
{
cout<<x;
x++;
}
The computer will output "0123...99"
The computer will output "0123...100"
The output is undefined
Question #31
Will a C compiler always compile C++ code?
Yes.
No.
Only optimized compilers will compile C++ code.
Question #32
Which of the following is not a valid keyword:
public
protected
guarded
Question #33
What is the correct syntax for inheritance?
class aclass : public superclass
class aclass inherit superclass
class aclass <-superclass
Question #34
What does the following code snippet do: for(;;) ;
The snippet is illegal
It loops forever
It is ignored by compiler, but it is not illegal
Question #35
Of the numbers 12, 23, 9, and 28, which one would be at the top of a properly i
mplemented maxheap?
28
9
Any of them could be
Question #36
What does the line containing "break;" do in the following code?
void afunction()
{
if(1)
{
break;
a_function();
cout<<"Err";
}
}
Breaks out of the if statement
Exits the function
Nothing (Compiler error)
Question #37
To what value are pointers initialized?
NULL
Newly allocated memory
No action is taken by the compiler to initialize pointers.
Question #38
What is the last index number in an array of 100 chars?
100
99
101
Question #39
Would you rather wait for the results of a quicksort, a linear search, or a bub
ble sort on a 200000 element array?
Quicksort
Linear Search
Bubble Sort
Question #40
Which of the following data structures uses the least memory?
struct astruct
{
int x;
float y;
int v;
};
union aunion
{
int x;
float v;
};
char array[10];
Question #41
What does the following code do? void afunction(int *x)
{
x=new int;
*x=12;
}
int main()
{
int v=10;
afunction(&v);
cout<<v;
}
Outputs 12
Outputs 10
Outputs the address of v
Question #42
To what value do nonglobal variables default?
auto
register
static
Question #43
Which header file allows file I/O with streams?
iostream
fstream
fileio.h
Question #44
What is the outcome of the line of code "cout<<abs(-16.5);"?
16
17
16.5
Question #45
What value will "strcmp("Astring", "Astring");" return?
A positive value
A negative value
Zero
Question #46
Evaluate !(1&&1||1&&0)
Error
True
False
Question #47
What header file is needed for the function exit()?
stdlib.h
conio.h
dos.h
Question #48
What ANSI C++ function clears the screen?
clrscr()
clear()
There is no function, defined by the ANSII C++ standard, which will clear the sc
reen
Question #49
When run on a computer, will a recursive function without an end condition ever
quit?
Compiler-Specific (Some compilers can convert these functions to infinite loops)
No
Yes
Question #50
How long does the following code run? for(int x=0; x=3; x++)
Never
Three times
Forever

You might also like