0% found this document useful (0 votes)
16 views

MCQ 2022

MCQ Questions programming

Uploaded by

morased002
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

MCQ 2022

MCQ Questions programming

Uploaded by

morased002
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Answer the following MCQ questions:

1. A C++ code line ends with .


a) A Semicolon (;)
b) A Fullstop(.)
c) A Comma (,)
d) A Slash (/)

2. variable of the same data type can be


declared in a single declaration statement.
a) Two
b) Three
c) Only one
d) More than one

3. The body of function contains .


a) Return statement
b) A variable declaration part
c) Processing part
d) All the above

4. Which one of the following is a keyword?


a) Size
b) Key
c) Jump
d) Switch

5. Float and double are related to data type.


a) Void
b) Floating
c) Fixed
d) Integral

6. Variable names must begin with .


a) #
b) $
c) Number
d) Letter
7. Which punctuator is used to group a set of C++
statements?
a) {}
b) []
c) ()
d) <>

8. The modulus operator uses ___ character.


a) +
b) *
c) /
d) %

9. Which operator is used to compare numerical


values?
a) Relational
b) Conditional
c) Assignment
d) Arithmetic

10. A variable defined within a block is visible


a) From the point of definition on ward in the
block
b) From the point of definition on ward in the
function
c) From the point of definition on ward in the
program
d) Throughout the function

11. Which of the following is the correct syntax to print the


message in C++ language?
a) cout <<"Hello world! ;
b) Cout << Hello world! ;
c) cout <<" Hello world! ";
d) None of the above

12. For inserting a new line in C++ program, which one of


the following statements can be used?
a) \n
b) \r
c) \a
d) None of the above

13. Which one of the following represents the tab?


a) \n
b) \t
c) \r
d) \a

14. If we stored five elements or data items in an array,


what will be the index address or the index number of
the array's last data item?
a) 3
b) 5
c) 4
d) 88
15. Which of the following is the correct syntax for declaring
the array?
a) init array []
b) int array [5];
c) Array[5];
d) int array;

16. Which of the following is the correct syntax for printing


the address of the first element?
a) array[0];
b) array[1];
c) array[2];
d) None of the above

17. The output of the following code is


#include <iostream>
using namespace std;
int main(){
int x = 100;
cout<< x++ <<"," ;
cout<< ++x <<",";
cout<< --x ;
}
a) 101,102,101
b) 100,102,102
c) 100,102,101
d) 100,100,100

18. The output of the following code is


#include <iostream>
using namespace std;
int main(){
int y;
cout<< "Please enter a number: " ;
cin>> y*5 ;
}
a) y*5
b) 5
c) Error
d) None of the above

19. The output of the following code is


#include <iostream>
using namespace std;
int main(){
int array[] = {10, 5, 6, 8};
cout<< array[2]++ <<"," ;
cout<< array[2]*5;
}
a) 6,30
b) 5,25
c) 5,30
d) 6,35

20. What is the value of z when input "Welcome in FCI"


#include <iostream>
using namespace std;
int main(){
string z ;
cin>>z ;
}
a) Welcome in FCI
b) Welcome
c) in FCI
d) FCI

21. The value of x from the following code is


#include <iostream>
using namespace std;
int main(){
float x;
cout>> "enter number: " ;
cin<< x ;
}
a) The input value
b) 3
c) Error
d) None of the above

22. The output of the following code is


#include <iostream>
using namespace std;
int main(){
char list[] = {'F', 'B', 'I'};
cout<< list[0] << ++list[1] << list[2]--;
}
a) FBI
b) FCH
c) FCI
d) FBH

23. The output of the following code is


#include <iostream>
using namespace std;
int main(){
cout<< "o\ne \two \th\ree\?\a" ;
}
a) o
ee? wo h
b) o\ne \two \th\ree\?\a
c) one two three
d) o
e wo hee?

24. The output of the following code is


#include <iostream>
using namespace std;
int main(){
int x = 5, y = 8;
cout<< x + y <<"," ;
cout<< "x + y" <<",";
cout<< 'x' + 'y' ;
}
a) 13,13,13
b) 13,x + y,241
c) Error
d) None of the above

25. The output of the following code is


#include <iostream>
using namespace std;
void print(string message){
cout<<message;
}
int main(){
print("Hello world");
}
int main(){
print("Hello world");
}
a) Hello world
b) Hello world Hello world
c) message
d) Error
26. What can be used to input a string with blankspace?
a) inline
b) getline
c) putline
d) cin

27. When will the cin can start proceessing of input?


a) After pressing enter key
b) BY pressing blankspace key
c) Both a & b
d) None of the above

28. Where does a cin stops it extraction of data?


a) By seeing a blankspace
b) By seeing letter
c) By seeing number
d) None of the above

29. Where does the execution of the program starts?


a) user-defined function
b) main function
c) void function
d) none of the above

30. What are mandatory (‫ )إلزامي‬parts in function


declaration?
a) return type,function name
b) return type,function name,parameters
c) both a and b
d) none of the above

31. How many minimum number of functions are need to


be presented in c++?
a) 0
b) 1
c) 2
d) 3

32. What will happen when we use void in function


declaration?
a) It will not return value to its caller
b) It will return value to its caller
c) both a & b
d) none of the above

33. Which keyword is used to access the variable in


namespace?
a) const
b) dynamic
c) using
d) static

34. The output of the following code is


#include <iostream>
using namespace std;
int main(){
int w;
w = 5*2+9;
cout<< w ;
}
a) 55
b) 50
c) 20
d) 19

35. The output of the following code is


#include <iostream>
using namespace std;
int main(){
int n=100;
for ( ; ;)
cout << n;
}
a) 100
b) Error
c) Infinity loop
d) None of the above
36. The switch statement is also called as?
a) repeating structure
b) selective structure
c) certain structure
d) bitwise structure

37. How many main types of loops are there in C++?


a) 4
b) 2
c) 3
d) 1

38. How many types of comments are there in C++?


a) 0
b) 1
c) 3
d) 2

39. What is a comment in c++?


a) comments are parts of the source code
disregarded by the compiler
b) comments are executed by the compiler to find the
meaning of the comment
c) comments are executable
d) comments are executed by the compiler.

40. What is used to write single line comment in c++?


a) /* …. */
b) /$ …. $/
c) //
d) /$ …. */
41. Which of the following is a correct declare variable?
a) Int variable_name
b) int variable_name;
c) variable_name int;
d) All of above
42. Which of the following is a correct variable name?
a) while
b) variable name
c) variable_name
d) Both b & c
43. Which of the following is a correct variable name?
a) VariableName2
b) variableName
c) variable_name
d) All of above

44. What does the following statement mean?


void p;
a) variable p is of type void
b) p is an object of type void
c) declares a variable with value p
d) Error

45. Which of the following will not return a value?


a) Null
b) Void
c) empty
d) free

46. Which is correct order for the size of the following data
types?
a) char > int < float
b) int < char > float
c) double < int < float
d) char < int < double

47. Which one holds the values or constants in


memory boxes?
a) Variable
b) While
c) Goto
d) Switch

48. In which type of constant the Decimal numbers,


integer and floating-point are related?
a) Numeric
b) String
c) Char
d) Boolean
49. function argument is a
a) Value sent to function by the calling program
b) Value returned by the function to the calling
program
c) Variable in the function that receives a value
from the calling program
d) Way that functions resist accepting the calling
program’s values

50. The break statement causes an exit


a) From the most loop or switch
b) Only from the most switch
c) Only from the most loop
d) From all loops and switches

51. array[7] is which element of the array?


a) Sixth
b) Seventh
c) Eighth
d) None of the above.

52. refers to the process of changing the data


type of the value stored in a variable.
a) Type char
b) Type int
c) Type float
d) Type casting

53. The body of function contains .


a) Return statement
b) A variable declaration
c) Processing part
d) All the above

54. The statement int A; b; is invalid because


a) Variables should be separated by Comma
b) Capital A is not allowed
c) Only one variable should be given
d) All of these
55. Binary plus (+) and Binary minus (-) are operator.
a) Arithmetic.
b) Relational.
c) Logical.
d) Assignment

56. constant is a signed real number.


a) Char
b) String
c) Integer
d) Floating point

57. Which of the following is real number?


a) 52
b) 5.2
c) 0.97
d) Both b & c

58. Which of the following is not a C++ keyword?


a) else
b) break
c) Cont
d) if

59. Operator requires two operands.


a) Logical
b) Binary
c) Unary
d) Ternary

60. Which is a conditional operator?


a) *
b) %
c) ?:
d) ""

61. What is a constant that contains a single


character enclosed within single quotes?
a) Character
b) Numeric
c) Fixed
d) Floating point
62. Logical AND (&&) and Logical OR (||)
are operators.
a) Logical
b) Equality
c) Arithmetic
d) Assignment

63. Consider the following statements:


int x = 22,y=15;
x = (x>y) ? (x+y) : (x-y);
What will be the value of x after executing these statements?
a) 22
b) 37
c) 7
d) Error

64. while(condition), what should condition be to do infinity


loop?
a) Negative numbers only
b) Positive numbers only
c) Zero only
d) All negative and positive numbers except zero.

65. If the variable count exceeds(‫ )يتجاوز‬100, a single


statement that prints "Too many" is
a) if (count<100) cout << "Too many";
b) if (count>100) cout >> "Too many";
c) if (count>100) cout << "Too many";
d) None of the above.

66. A switch construct can be used with which of the


following types of variable?
a) int
b) int, char
c) int, float, char
d) Any basic datatype
67. Consider the following loop :
for(int i=0; i<8; i++)
What will be the value of i after loop finish?
a) 9
b) 7
c) 8
d) Error

68. Choose a correct C++ for loop header syntax.


a) for(initalization; condition; increment/decrement)
b) for(declaration, condition, incrementoperation)
c) for(declaration; incrementoperation; condition)
d) for{initalization; condition; incrementoperation}

69. Choose a correct C++ do while syntax.


a) dowhile(condition) { statements };
b) do while(condition) { statements };
c) do { statements } while(condition)
d) do { statements } while(condition);

70. Which of the following is an entry-controlled loop?


a) For loop
b) While loop
c) Do while loop
d) Both a & b

71. Which of the following is an exit-controlled loop?


a) While loop
b) For loop
c) Do while loop
d) Both b & c

72. Decision Control statements in C++ can be


implemented using
a) if
b) if-else
c) Conditional Operator
d) All of the above
73. If you have to make decision based on multiple
choices, which of the following is best choose?
a) if
b) if-else
c) if-else-if
d) All of the above

74. Can we use string inside switch statement?


a) Yes
b) No

75. In situations where we need to execute body of the loop


before testing the condition, we should use .
a) For loop
b) while loop
c) do-while loop
d) nested for loop

76. Loops in C++ Language are implemented using?


a) While loop
b) For loop
c) Do while loop
d) All of the above

77. Can a for loop contain another for loop?


a) Yes
b) No
78. What should be the location of "using namespace std;"
in c++ code?
a) Before all #include
b) After #include<iostream>
c) In middle of #includes
d) After all #include

79. Which operator has highest precedence in ( * / % )?


a) /
b) %
c) *
d) all have same precedence
80. Which operator has highest precedence?
a) ()
b) =
c) *
d) ++

You might also like