Which of the following is the correct syntax to output "Hello World" in C++?
a)echo "Hello World";
b)Console.WriteLine("Hello World");
c)cout << "Hello World";
d)printf("Hello World");
Answer: c-
Which of the following is not a C++ keyword?
a)public
b)private
c)protected
d)then
Answer: d -
Which of the following is the correct file extension for C++ source files?
a).cp
b).cpp
c).cxx
d) Both b and c
Answer: d -
What is the default return type of a function in C++ if not specified?
a)int
b)void
c)float
d)double
Answer: a -
Which of the following is used to comment a single line in C++?
a)/* comment */
b)// comment
c)# comment
d)-- comment
Answer: b -
Which header file is required for using
cout
andcin
?
a)<iostream.h>
b)<stdio.h>
c)<iostream>
d)<conio.h>
Answer: c -
Which of the following is not a basic data type in C++?
a)int
b)float
c)bool
d)real
Answer: d -
Which operator is used for scope resolution in C++?
a)::
b).
c)->
d):
Answer: a -
Which of the following is the correct way to declare a constant in C++?
a)const int x = 10;
b)int const x = 10;
c)#define x 10
d) All of the above
Answer: d -
What does the
main()
function return in C++ by default?
a)1
b)0
c)void
d)None
Answer: b
11–20: Control Structures
-
Which loop is guaranteed to execute at least once?
a)for
b)while
c)do-while
d) None of the above
Answer: c -
Which statement is used to skip the current iteration in a loop?
a)exit
b)break
c)continue
d)return
Answer: c -
What is the output of:
for(int i=0;i<5;i++){ cout << i; }
?
a) 12345
b) 01234
c) 1234
d) 012345
Answer: b -
Which keyword is used to return a value from a function?
a)break
b)goto
c)return
d)exit
Answer: c -
Which of the following is used to terminate a
switch
statement?
a)return
b)exit
c)break
d)goto
Answer: c -
What is the purpose of the
default
keyword in a switch case?
a) It ends the switch block.
b) It is executed if no other case matches.
c) It is always executed first.
d) None of the above
Answer: b -
Which of the following is not a relational operator?
a)!=
b)==
c)=
d)>=
Answer: c -
Which of the following loops is entry-controlled?
a)do-while
b)while
c) Both a and b
d) None
Answer: b -
What is the output of:
if (0) cout << "Hi"; else cout << "Bye";
?
a) Hi
b) Bye
c) 0
d) Error
Answer: b -
Which operator is used to check both conditions in an
if
statement?
a)&
b)&&
c)|
d)||
Answer: b
0 Comments