Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
Filter by Categories
nmims post
Objective Type Set
Online MCQ Assignment
Question Solution
Solved Question
Uncategorized

Multiple choice question for engineering

Set 1

1. The data elements in structure are also known as what?
a) objects
b) members
c) datas
d) none of the mentioned

View Answer

Answer: b

2. What will be used when terminating a structure?
a) :
b) }
c) ;
d) ;;

View Answer

Answer: c [Reason:] While terminating a structure, a semi colon is used to end this up.

3. What will happen when the structure is declared?
a) it will not allocate any memory
b) it will allocate the memory
c) it will be declared and initialized
d) none of the mentioned

View Answer

Answer: a [Reason:] While the structure is declared, it will not be initialized, So it will not allocate any memory.

4. The declaration of structure is also called as?
a) sructure creator
b) structure signifier
c) structure specifier
d) none of the mentioned

View Answer

Answer: c [Reason:] The structure declaration with open and close braces and with a semicolon is also called structure specifier.

5. What is the output of this program?

  1.     #include <iostream>
  2.     #include <string.h>
  3.     using namespace std;
  4.     int main()
  5.     {
  6.         struct student 
  7.         {
  8.             int num;
  9.             char name[25];
  10.         };
  11.         student stu;
  12.         stu.num = 123;
  13.         strcpy(stu.name, "John");
  14.         cout << stu.num << endl;
  15.         cout << stu.name << endl;
  16.         return 0;
  17.     }

a) 123
    john
b) john
    john
c) compile time error
d) none of the mentioned

View Answer

Answer: a [Reason:] We are coping the value john to the name and then we are printing the values that are in the program. Output: $ g++ stu.cpp $ a.out 123 john

6. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     struct Time 
  4.     {
  5.         int hours;
  6.         int minutes;
  7.         int seconds;
  8.     };
  9.     int toSeconds(Time now);
  10.     int main()
  11.     {
  12.         Time t;
  13.         t.hours = 5;
  14.         t.minutes = 30;
  15.         t.seconds = 45;
  16.         cout << "Total seconds: " << toSeconds(t) << endl;
  17.         return 0;
  18.     }
  19.     int toSeconds(Time now)
  20.     {
  21.         return 3600 * now.hours + 60 * now.minutes + now.seconds;
  22.     }

a) 19845
b) 20000
c) 15000
d) 19844

View Answer

Answer: a [Reason:] In this program, we are just converting the given hours and minutes into seconds. Output: $ g++ stu1.cpp $ a.out Total seconds:19845

7. What will be the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         struct ShoeType 
  6.         {
  7.            string style;
  8.            double price;
  9.         };
  10.          ShoeType shoe1, shoe2;
  11.          shoe1.style = "Adidas";
  12.          shoe1.price = 9.99;
  13.          cout << shoe1.style << " $ "<< shoe1.price;
  14.          shoe2 = shoe1;
  15.          shoe2.price = shoe2.price / 9;
  16.          cout << shoe2.style << " $ "<< shoe2.price;
  17.          return 0;
  18.     }

a) Adidas $ 9.99
    Adidas $ 1.11
b) Adidas $ 9.99
    Adidas $ 9.11
c) Adidas $ 9.99
    Adidas $ 11.11
d) none of the mentioned

View Answer

Answer: a [Reason:] We copied the value of shoe1 into shoe2 and divide the shoe2 value by 9, So this is the output. Output: $ g++ stu2.cpp $ a.out Adidas $ 9.99 Adidas $ 1.11

8. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     struct sec 
  4.     {
  5.         int a;
  6.         char b;
  7.     };
  8.     int main()
  9.     {
  10.         struct sec s ={25,50};
  11.         struct sec *ps =(struct sec *)&s;
  12.         cout << ps->a << ps->b;
  13.         return 0;
  14.     }

a) 252
b) 253
c) 254
d) 262

View Answer

Answer: a [Reason:] In this program, We are dividing the values of a and b, printing it. Output: $ g++ stu5.cpp $ a.out 252

9. Which of the following is a properly defined structure?
a) struct {int a;}
b) struct a_struct {int a;}
c) struct a_struct int a;
d) struct a_struct {int a;};

View Answer

Answer: d [Reason:] The a_struct is declared as structure name and its data element is a.

10. Which of the following accesses a variable in structure *b?
a) b->var;
b) b.var;
c) b-var;
d) b>var;

View Answer

Answer: a [Reason:] Because in a structure pointer, the data element is declared as above only.

Set 2

1. What is the size of wchar_t in C++?
a) 2
b) 4
c) 2 or 4
d) based on the number of bits in the system

View Answer

Answer: d [Reason:] Compiler wants to make CPU as more efficient in accessing the next value.

2. Pick the odd one out
a) array type
b) character type
c) boolean type
d) integer type

View Answer

Answer: a [Reason:] Array type is not the basic type and it is constructed using the basic type.

3. Which datatype is used to represent the absence of parameters?
a) int
b) short
c) void
d) float

View Answer

Answer: c [Reason:] void will not return anything.

4. What does a escape code represent?
a) alert
b) backslash
c) tab
d) form feed

View Answer

Answer: a [Reason:] Because a is used to produce a beep sound.

5. Which type is best suited to represent the logical values?
a) integer
b) boolean
c) character
d) all of the mentioned

View Answer

Answer: b [Reason:] Logical values can be either true or false, so the boolean type is suited for it.

6. Identify the user-defined types from the following?
a) enumeration
b) classes
c) both enumeration and classes
d) int

View Answer

Answer: c [Reason:] They must be defined by the users before use unlike the other types which are readily available.

7. Which of the following statements are true?
    int f(float)
a) f is a function taking an argument of type int and retruning a floating point number
b) f is a function taking an argument of type float and returning a integer
c) f is a function of type float
d) none of the mentioned

View Answer

Answer: b [Reason:] The argument that is passed to a function f is of float type and the function finally retruns a value that id is of integer type.

8. The value 132.54 can represented using which data type?
a) double
b) void
c) int
d) bool

View Answer

Answer: a [Reason:] The given value is with decimal points, so float or double can be used.

9. When a language has the capability to produce new data type mean, it can be called as
a) overloaded
b) extensible
c) encapsulated
d) reprehensible

View Answer

Answer: b [Reason:] Extensible is used to add new features to C++.

10. Pick the odd one out.
a) integer, character, boolean, floating
b) enumeration, classes
c) integer, enum, void
d) arrays, pointer, classes

View Answer

Answer: c [Reason:] Option a consists of all fundamental types, option b consists of user-definied types and option d consists of derived types but option c is a mixture.

Set 3

1. How many types of comments are there in c++?
a) 1
b) 2
c) 3
d) 4

View Answer

Answer: b [Reason:] There are two types of comments. They are double slash and slash stared.

2. What is a comment in c++?
a) comments are parts of the source code disregarded by the compiler
b) comments are executed by compiler to find the meaning of the comment
c) comments are executable
d) none of the mentioned

View Answer

Answer: a [Reason:] Comments are used to add meaning to the program.

3. What type of comments does c++ support?
a) single line
b) multi line
c) single line and multi line
d) none of the mentioned

View Answer

Answer: c

4. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         /* this is comment*
  6.         cout << "hello world";
  7.         return 0;
  8.     }

a) hello world
b) hello
c) compile time error
d) none of the mentioned

View Answer

Answer: c [Reason:] Because the slash should need to be forward not backward.

5. What is used to write multi line comment in c++?
a) /* …. */
b) /$ …. $/
c) //
d) none of the mentioned

View Answer

Answer: a [Reason:] The /* is used to write the multi line comment.

6. What is the use of the indentation in c++?
a) distinguishes between comments and code
b) r distinguishes between comments and outer data
c) both a and b
d) none of the mentioned

View Answer

Answer: a

7. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     long factorial (long a)
  4.     {
  5.         if (a > 1)
  6.             return (a * factorial (a + 1));
  7.         else
  8.             return (1);
  9.     }
  10.     int main ()
  11.     {
  12.         long num = 3;
  13.         cout << num << "! = " << factorial ( num );
  14.         return 0;
  15.     }

a) 6
b) 24
c) segmentation fault
d) compile time error

View Answer

Answer: c [Reason:] As we have given in the function as a+1, it will exceed the size and so it arises the segmentation fault. Output: $ g++ arg3.cpp $ a.out segmentation fault

8. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     void square (int *x)
  4.     {
  5. 	*x = (*x + 1) * (*x);
  6.     }
  7.     int main ( )
  8.     {
  9. 	int num = 10;
  10.         square(&num);
  11. 	cout << num;
  12. 	return 0;
  13.     }

a) 100
b) compile time error
c) 144
d) 110

View Answer

Answer: d [Reason:] We have increased the x value in operand as x + 1, so it will return as 110. Output: $ g++ arg2.cpp $ a.out 110

9. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     int add(int a, int b);
  4.     int main()
  5.     {
  6.         int i = 5, j = 6;
  7.         cout << add(i, j) << endl;
  8.         return 0;
  9.     }
  10.     int add(int a, int b )
  11.     {
  12.         int sum = a + b;
  13.         a = 7;
  14.         return a + b;
  15.     }

a) 11
b) 12
c) 13
d) compile time error

View Answer

Answer: c [Reason:] The value of a has been changed to 7, So it returns as 13. Output: $ g++ arg1.cpp $ a.out 13

10. What will happen when we use void in argument passing?
a) It will not return value to its caller
b) It will return value to its caller
c) Maybe or maynot be return value to its caller
d) None of the mentioned

View Answer

Answer: a [Reason:] As void is not having any return value, it will not return the value to the caller.

11. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     void Sum(int a, int b, int & c)
  4.     {
  5.         a = b + c;
  6.         b = a + c;
  7.         c = a + b;
  8.     }
  9.     int main()
  10.     {
  11.         int x = 2, y =3;
  12.         Sum(x, y, y);
  13.         cout << x << " " << y;
  14.         return 0;
  15.     }

a) 2 3
b) 6 9
c) 2 15
d) compile time error

View Answer

Answer: c [Reason:] We have passed three values and it will manipulate according to the given condition and yield the result as 2 15. Output: $ g++ arg.cpp $ a.out 2 15

Set 4

1. Which value we cannot assign to reference?
a) integer
b) floating
c) unsigned
d) null

View Answer

Answer: d [Reason:] If it can be assigned with a null value means, it is a copy of pointer.

2. Identify the incorrect statement
a) Reference is the alternate name of the object
b) A reference value once defined can be reassigned
c) A reference value once defined cannot be reassigned
d) None of the mentioned

View Answer

Answer: b [Reason:] Reference is a thing which points to valid memory address, so it can’t be redesigned.

3. Which reference modifier is used to define reference variable?
a) &
b) $
c) #
d) none of the mentioned

View Answer

Answer: a

4. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     void swap(int &a, int &b);
  4.     int main()
  5.     {
  6.         int a = 5, b = 10;
  7.         swap(a, b);
  8.         cout << "In main " << a << b;
  9.         return 0;
  10.     }
  11.     void swap(int &a, int &b)
  12.     {
  13.         int temp;
  14.         temp = a;
  15.         a = b;
  16.         b = temp;
  17.         cout << "In swap " << a << b;
  18.     }

a) In swap 105 In main 105
b) In swap 105 In main 510
c) In swap 510 In main 105
d) None of the mentioned

View Answer

Answer: a [Reason:] As we are calling by reference the values in the address also changed. So the main and swap values also changed. Output: $ g++ ref.cpp $ a.out In swap 105 In main 105

5. What does a reference provide?
a) Alternate name for the class
b) Alternate name for the variable
c) Alternate name for the pointer
d) None of the mentioned

View Answer

Answer: b [Reason:] Because we are pointing memory address using temp variable.

6. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int a = 9;
  6.         int & aref = a;
  7.         a++;
  8.         cout << "The value of a is " << aref;
  9.         return 0;
  10.     }

a) 9
b) 10
c) error
d) 11

View Answer

Answer: b [Reason:] The value is declared and it is post incremented, so it’s value is 10. $ g++ ref1.cpp $ a.out 10

7. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     void print (char * a)
  4.     {
  5.         cout << a << endl;
  6.     }
  7.     int main ()
  8.     {
  9.         const char * a = "Hello world";
  10.         print(const_cast<char *> (a) );
  11.         return 0;
  12.     }

a) Hello world
b) Hello
c) world
d) compile time error

View Answer

Answer: a [Reason:] In this program we used the concept of constant casting to cast the variable and printing it. Output: $ g++ ref2.cpp $ a.out Hello world

8. Identify the correct sentence regarding inequality between reference and pointer.
a) we can not create the array of reference
b) we can create the Array of reference
c) we can use reference to reference
d) none of the mentioned

View Answer

Answer: a

Set 5

1. Is bool a fundamental datatype in C++?
a) Yes
b) No, it is a typedef of unsigned char
c) No, it is an enum of {false, true}
d) No, it is expanded from macros

View Answer

Answer: a [Reason:] C++ has bool as a fundamental data type.

2. Find the odd one out:
a) std::vector<int>
b) std::vector<short>
c) std::vector<long>
d) std::vector<bool>

View Answer

Answer: d [Reason:] std::vector<bool> is a specialized version of vector, which is used for elements of type bool and optimizes for space. It behaves like the unspecialized version of vector and the storage is not necessarily an array of bool values, but the library implementation may optimize storage so that each value is stored in a single bit.

3. What is the value of the bool?

  1. bool is_int(789.54)

a) True
b) False
c) 1
d) None of the mentioned

View Answer

Answer: b [Reason:] The given number is a double not an integer, so the function returns 0 which is boolean false.

4. What happens when a null pointer is converted into bool?
a) an error is flagged
b) bool value evaluates to true
c) bool value evaluates to false
d) the statement is ignored

View Answer

Answer: c [Reason:] A pointer can be implicitly converted to a bool. A nonzero pointer converts to true and zerovalued pointer converts to false.

5. Which of the following statements are false?
a) bool can have two values and can be used to express logical expressions
b) bool cannot be used as the type of the result of the function
c) bool can be converted into integers implicitly
d) a bool value can be used in arithmetic expressions

View Answer

Answer: b

6. For what values of the expression is an if-statement block not executed?
a) 0 and all negative values
b) 0 and -1
c) 0
d) 0, all negative values, all positive values except 1

View Answer

Answer: c [Reason:] The if-statement block is only not executed when the expression evaluates to 0. It’s just syntactic sugar for a branch-if-zero instruction.

7. Which of the two operators ++ and — work for the bool datatype in C++?
a) None
b) ++
c) —
d) ++ & —

View Answer

Answer: b [Reason:] Due to history of using integer values as booleans, if an integer is used as a boolean, then incrementing will mean that whatever its truth value before the operation, it will have a truth-value of true after it. However, it’s not possible to predict the result of — given knowledge only of the truth value of x, as it could result in false.

8. What is the output of the following program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     int f(int p, int q)
  4.     {
  5.         if (p > q)
  6.             return p;
  7.         else
  8.             return q;
  9.     }
  10.     main()
  11.     {
  12.         int a = 5, b = 10;
  13.         int k;
  14.         bool x = true;
  15.         bool y = f(a, b);
  16.         k =((a * b) + (x + y));
  17.         cout << k;
  18.     }

a) 55
b) 62
c) 52
d) none of the mentioned

View Answer

Answer: c

9. What is the value of p?

  1.     #include <iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int p;
  6.         bool a = true;
  7.         bool b = false;
  8.         int x = 10;
  9.         int y = 5;
  10.         p = ((x | y) + (a + b));
  11.         cout << p;
  12.         return 0;
  13.     }

a) 0
b) 16
c) 12
d) 2

View Answer

Answer: b

10. Evaluate the following
(false && true) || false || true
a) 0
b) 1
c) false
d) none of the mentioned

View Answer

Answer: b

.woocommerce-message { background-color: #98C391 !important; }