Академический Документы
Профессиональный Документы
Культура Документы
66
C. .1
D. -1
E. All of the above
BASICS OF C++
Set 1
Questions
Question 9.
Question 1.
Question 2.
Question 3.
What punctuation is used to signal the beginning
and end of code blocks?
A. { }
B. -> and <C. BEGIN and END
D. ( and )
Question 4.
Question 5.
Question 6.
Question 7.
Which of the following is the correct operator to
compare two variables?
A. :=
B. =
C. equal
D. ==
Question 8.
Question 10.
Evaluate !(1 && !(0 || 1)).
A. True
B. False
C. Unevaluatable
Answers
1. C. 0
2. C. main()
3. A. { }
4. B. ;
5. C. /* Comment */
6. B. real
7. D. ==
8. E. All of the above
9. B. &&
10. A. True
Set 2
Questions
Question 1
Question 2
d.
Question 3
Question 4
Page 1 of 7
10.
line
Set 3
Questions
Question 5
Question 1
Question 6
Which of the following is false?
a. Cout represents the standard output stream in
c++.
b. Cout is declared in the iostream standard file
c. Cout is declared within the std namespace
d. None of above
Question 7
A Semicolon (
d.
A colon (
Question 8
Question 9
A variable is/are
a. String that varies during program execution
b. A portion of memory to store a determined
value
c. Those numbers that are frequently required in
programs
d. None of these
Question 2
Which of the following can not be used as
identifiers?
a. Letters
b. Digits
c. Underscores
d. Spaces
Question 3
Question 4
Which of the following can not be used as valid
identifier?
a. bitand
b. bittand
c. biand
d. band
Question 5
Question 10
Answers
1. b. All lines beginning with two slash signs are
considered comments.
2. c. Number Sign (#)
3. a. The declarations of the basic standard
input-output library.
4. c. Main()
5. b. Parenthesis
6. d. None of above
7. c. A semicolon
8. d. They end with a semicolon
9. b. Starting with /* and ending with */
Question 6
Question 7
Page 2 of 7
Question 8
Question 9
Question 10
In an assignment statement
a. The lvalue must always be a variable
b. The rvalue might be a constant, a variable, an
expression or any combination of these
c. The assignment always takes place from right
to left and never the other way
d. All of above
Answers
1.
b. A portion of memory to store a determined
value
2.
d. Spaces
3.
c. Typename
4.
a. Bitand
5.
a. The first one refers to a variable whose
identifier is x and the second one refers to the
character constant x
6.
d. \w
7.
d. All of above
8.
c. It is a C++ statement that declares a
constant in C++
9. c. Declares a constant pathwidth whose value
will be 100
10. d. All of above
Set 4
Questions
Question 1
In an assignment statement
a=b;
Which of the following statement is true?
a. The variable a and the variable b are equal.
Question 2
All of the following are valid expressions in C++
a = 2 + (b = 5);
a = b = c = 5;
a = 11 % 3
a. True
b. False
Question 3:
To increase the value of c by one which of the
following statement is wrong?
a. c++;
b. c = c + 1;
c. c + 1 => c;
d. c += 1
Question 4:
When following piece of code is executed, what
happens?
b = 3;
a = b++;
a. a contains 3 and b contains 4
b. a contains 4 and b contains 4
c. a contains 4 and b contains 3
d. a contains 3 and b contains 3
Question 5:
The
a.
b.
c.
d.
Question 6:
Which of the following is not a valid relational
operator?
a. ==
b. =>
c. >=
d. >=
Question 7:
Question 8:
When does the code block following while(x<100)
execute?
A. When x is less than one hundred
B. When x is greater than one hundred
C. When x is equal to one hundred
D. While it wishes
Page 3 of 7
a.
b.
c.
d.
Question 9:
Question 5:
Question 10:
Answers
1. b. The value of b is assigned to variable a but
the later changes on variable b will not effect the
value of variable a
2. a. True
3. c. c + 1 => c;
4. a. a contains 3 and b contains 4
5. a. either True or False
6. b. =>
7. A. 10
8. A. When x is less than one hundred
9. D. Repeat Until
10. C. 1
Set 5
c.
d.
a.
b.
c.
d.
a.
b.
c.
d.
a.
c.
d.
a.
b.
c.
d.
Question 10:
a.
b.
c.
d.
Answers
Question 4:
Question 9:
Question 3:
a.
b.
Question 8:
Question 2
a.
b.
c.
d.
Question 7:
d.
Streams are
Abstraction to perform input and output
operations in sequential media
Abstraction to perform input and output operations
in direct access media
Objects where a program can either insert or
extract characters to and from it
Both a and c
Question 6:
c.
Question 1
b.
a.
b.
c.
d.
b.
Questions
a.
print
write
cout
cin
1.
2.
3.
4.
5.
6.
7.
d. Both a and c
c. <<
b. Both are similar but endl additionally performs
flushing of buffer
c. Cout
a. Cin
b. Monitor
a. Keyboard
Page 4 of 7
8. d. All of above
9. d. >>
10. d. all of above
b.
The program worked as expected without
any errors during its execution
c.
not to end the program yet.
d.
None of above
Set 6
Question 8:
Which of the following is not a reserve keyword in
C++?
a.
mutable
b.
default
c.
readable
d.
volatile
Questions
Question 1:
cin extraction stops execution as soon as it finds
any blank space character
a.
true
b.
false
Question 9:
The size of following variable is not 4 bytes in 32
bit systems
a.
int
b.
long int
c.
short int
d.
float
Question 2:
Observe the following statements and decide what
do they do.
string mystring;
getline(cin, mystring);
a.
reads a line of string from cin into mystring
b.
reads a line of string from mystring into cin
c.
cin cant be used this way
d.
none of above
Question 10:
Identify the correct statement regarding scope of
variables
a.
Global variables are declared in a separate
file and accessible from any program.
b.
Local variables are declared inside a function
and accessible within the function only.
c.
Global variables are declared inside a
function and accessible from anywhere in program.
d.
Local variables are declared in the main body
of the program and accessible only from functions.
Question 3:
Regarding stringstream identify the invalid
statement
a.
stringstream is defined in the header file
<sstream>
b.
It allows string based objects treated as
stream
c.
It is especially useful to convert strings to
numerical values and vice versa.
d.
None of above
Answers
1.
a. True
2.
a. Reads a line of string from cin into
mystring
3.
d. None of above
4.
d. <sstream>
5.
c. <sstring>
6.
b. The second input overwrites the first one
7.
b. The program worked as expected without
any errors during its execution
8.
c. readable
9.
c. short int
10
b. Local variables are declared inside a
function and accessible within the function on
Question 4:
Question 5:
Set 7
Question 6:
If you use same variable for two getline
statements
a.
Both the inputs are stored in that variable
b.
The second input overwrites the first one
c.
The second input attempt fails since the
variable already got its value
d.
You can not use same variable for two
getline statements
Question 7:
The return 0; statement in main function
indicates
a.
The program did nothing; completed 0 tasks
Questions
Question 1:
a.
b.
c.
d.
Question 2:
Looping in a program means
Page 5 of 7
a.
b.
c.
d.
If (x==1){
Cout <<x is 1;
}
Else if (x==2){
Cout << x is 2;
}
Else{
Cout <<value of x unknown;
}
Question 3:
a.
b.
c.
d.
a.
b.
c.
d.
Question 9:
Question 4:
a.
b.
c.
d.
Question 5:
a.
b.
c.
d.
a.
b.
c.
d.
Question 7:
a.
b.
c.
d.
Question 8:
Code 1:
switch (x) {
case 1:
cout <<x is 1;
break;
case 2:
cout <<x is 2;
break;
default:
cout <<value of x unknown;
}
Code 2
a.
b.
c.
Question 6:
d.
Question 10
a.
b.
c.
d.
Answers
1.
2.
3.
4.
5.
6.
7.
8.
9.
1.
Page 6 of 7
Set 8
Question 8:
Questions
Question 1:
The void specifier is used if a function does not
have return type.
a.
True
b.
False
Question 9:
Question 2:
Question 10:
Question 3:
Type specifier is optional when declaring a function
a.
True
b.
False
Question 4:
Study the following piece of code and choose the
best answer
int x=5, y=3, z;
a=addition(x,y)
a.
The function addition is called by passing
the values
b.
The function addition is called by passing
reference
Question 5:
10.0
5.0
10.0
10
5.0
2.5
5
2.5
Answers
Question 6:
If the type specifier of parameters of a function is
followed by an ampersand (&
is
a.
pass by value
b.
pass by reference
Question 7:
In case of pass by reference
a.
The values of those variables are passed to
the function so that it can manipulate them
b.
The location of variable in memory is passed
to the function so that it can use the same memory
area for its processing
c.
The function declaration should contain
ampersand (&
in its type declaration
d.
All of above
1.
a. True
2.
b. False [ parameters can be empty without
void too!]
3.
b. False
4.
a. The function addition is called by passing
the values
5.
a. Any modifications to the variables x & y
from inside the function will not have any effect
outside the function
6.
b. pass by reference
7.
b. The location of variable in memory is
passed to the function so that it can use the same
memory area for its processing
8.
d. None of above
9.
b. False
10. d. 10
2.5
Page 7 of 7