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. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         float x = 0.1;
  5.         if (x == 0.1)
  6.             printf("Aidlo");
  7.         else
  8.             printf("Advanced C Classes");
  9.     }

a) Advanced C Classes
b) Aidlo
c) Run time error
d) Compile time error

View Answer

Answer: a

2. Comment on the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         float x = 0.1;
  5.         printf("%d, ", x);
  6.         printf("%f", x);
  7.     }

a) 0.100000, junk value
b) Junk value, 0.100000
c) 0, 0.100000
d) 0, 0.999999

View Answer

Answer: b

3. What is the output of this C code?
(7 and 8 are entered)

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         float x;
  5.         int y;
  6.         printf("enter two numbers n", x);
  7.         scanf("%f %f", &x, &y);
  8.         printf("%f, %d", x, y);
  9.     }

a) 7.000000, 7
b) Run time error
c) 7.000000, junk
d) Varies

View Answer

Answer: c

4. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         double x = 123828749.66;
  5.         int y = x;
  6.         printf("%dn", y);
  7.         printf("%lfn", y);
  8.     }

a) 0, 0.0
b) 123828749, 123828749.66
c) 12382874, 12382874.0
d) 123828749, 0.000000

View Answer

Answer: d

5. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int x = 97;
  5.         char y = x;
  6.         printf("%cn", y);
  7.     }

a) a
b) b
c) 97
d) Run time error

View Answer

Answer: a

6. When double is converted to float, the value is?
a) Truncated
b) Rounded
c) Depends on the compiler
d) Depends on the standard

View Answer

Answer: c

7. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         unsigned int i = 23;
  5.         signed char c = -23;
  6.         if (i > c)
  7.             printf("Yesn");
  8.         else if (i < c)
  9.             printf("Non");
  10.     }

a) Yes
b) No
c) Depends on the compiler
d) Depends on the operating system

View Answer

Answer: b

8. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int i = 23;
  5.         char c = -23;
  6.         if (i < c)
  7.             printf("Yesn");
  8.         else
  9.             printf("Non");
  10.     }

a) Yes
b) No
c) Depends on the compiler
d) Depends on the standard

View Answer

Answer: b

Set 2

1. Which of the following correctly declares an array?
a) int array[10];
b) int array;
c) array{10};
d) array array[10];

View Answer

Answer: a [Reason:] Because array variable and values need to be declared after the datatype only.

2. What is the index number of the last element of an array with 9 elements?
a) 9
b) 8
c) 0
d) Programmer-defined

View Answer

Answer: b [Reason:] Because the first element always starts at 0. So it is on 8 position.

3. What is a array?
a) An array is a series of elements of the same type in contiguous memory locations
b) An array is a series of element
c) An array is a series of elements of the same type placed in non-contiguous memory locations
d) None of the mentioned

View Answer

Answer: a

4. Which of the following accesses the seventh element stored in array?
a) array[6];
b) array[7];
c) array(7);
d) array;

View Answer

Answer: a [Reason:] The array location starts from zero, So it can accessed by array[6].

5. Which of the following gives the memory address of the first element in array?
a) array[0];
b) array[1];
c) array(2);
d) array;

View Answer

Answer: d

6. What will be the output of this program?

  1.     #include <stdio.h>
  2.     using namespace std;
  3.     int array1[] = {1200, 200, 2300, 1230, 1543};
  4.     int array2[] = {12, 14, 16, 18, 20};
  5.     int temp, result = 0;
  6.     int main()
  7.     {
  8.         for (temp = 0; temp < 5; temp++) 
  9.         {
  10.             result += array1[temp];
  11.         }
  12.         for (temp = 0; temp < 4; temp++)
  13.         {
  14.             result += array2[temp];
  15.         }
  16.         cout << result;
  17.         return 0;
  18.     }

a) 6553
b) 6533
c) 6522
d) 12200

View Answer

Answer: b [Reason:] In this program we are adding the every element of two arrays. Finally we got output as 6533. Output: $ g++ array.cpp $ a.out 6533

7. What will be the output of the this program?

  1.     #include <stdio.h>
  2.     using namespace std;
  3.     int main ()
  4.     {
  5.         int array[] = {0, 2, 4, 6, 7, 5, 3};
  6.         int n, result = 0;
  7.         for (n = 0; n < 8; n++) {
  8.             result += array[n];
  9.         }
  10.         cout << result;
  11.         return 0;
  12.     }

a) 25
b) 26
c) 27
d) None of the mentioned

View Answer

Answer: d [Reason:] We are adding all the elements in the array and printing it. Total elements in the array is 7, but our for loop will go beyond 7 and add a garbage value.

8. What is the output of this program?

  1.     #include <stdio.h>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int a = 5, b = 10, c = 15;
  6.         int arr[3] = {&a, &b, &c};
  7.         cout << *arr[*arr[1] - 8];
  8.         return 0;
  9.     }

a) 15
b) 18
c) garbage value
d) compile time error

View Answer

Answer: d [Reason:] The conversion is invalid in this array. So it will arise error. The following compilation error will be raised: cannot convert from ‘int *’ to ‘int’

9. What is the output of this program?

  1.     #include <stdio.h>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         char str[5] = "ABC";
  6.         cout << str[3];
  7.         cout << str;
  8.         return 0;
  9.     }

a) ABC
b) ABCD
c) AB
d) None of the mentioned

View Answer

Answer: a [Reason:] We are just printing the values of first 3 values. $ g++ array.cpp $ a.out ABC

10. What is the output of this program?

  1.     #include <stdio.h>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int array[] = {10, 20, 30};
  6.         cout << -2[array];
  7.         return 0;
  8.     }

a) -15
b) -30
c) compile time error
d) garbage value

View Answer

Answer: b [Reason:] It’s just printing the negative value of the concern element. $ g++ array.cpp $ a.out -30

Set 3

1. How many types of returning values are present in c++?
a) 1
b) 2
c) 3
d) 4

View Answer

Answer: c [Reason:] The three types of returning values are return by value, return by reference and return by address.

2. What will you use if you are not intended to get a return value?
a) static
b) const
c) volatile
d) void

View Answer

Answer: d [Reason:] Void is used to not to return anything.

3. Where does the return statement returns the execution of the program?
a) main function
b) caller function
c) same function
d) none of the mentioned

View Answer

Answer: b

4. What is the output of this program?

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

a) 5
b) 7
c) either 5 or 7
d) none of the mentioned

View Answer

Answer: b [Reason:] In this program, we are returning the maximum value by using conditional operator. Output: $ g++ ret.cpp $ a.out 7

5. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     double & WeeklyHours()
  4.     {
  5.         double h = 46.50;
  6.         double &hours = h;
  7.         return hours;
  8.     }
  9.     int main()
  10.     {
  11.         double hours = WeeklyHours();
  12.         cout << "Weekly Hours: " << hours;
  13.         return 0;
  14.     }

a) 46.5
b) 6.50
c) compile time error
d) none of the mentioned

View Answer

Answer: a [Reason:] We are returning the value what we get as input. Output: $ g++ ret1.cpp $ a.out 46.5

6. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     int mult (int x, int y)
  4.     {
  5.         int result;
  6.         result = 0;
  7.         while (y != 0) 
  8.         {
  9.             result = result + x;
  10.             y = y - 1;
  11.         }
  12.         return(result);
  13.     }
  14.     int main ()
  15.     {
  16.         int x = 5, y = 5;
  17.         cout  << mult(x, y) ;
  18.         return(0);
  19.     }

a) 20
b) 25
c) 30
d) 35

View Answer

Answer: b [Reason:] We are multiplying these values by adding every values. Output: $ g++ ret.cpp $ a.out 25

7. When will we use the function overloading?
a) same function name but different number of arguments
b) different function name but same number of arguments
c) same function name but same number of arguments
d) different function name but different number of arguments

View Answer

Answer: a [Reason:] In function overloading, we can use any number of arguments but same function name.

8. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     int gcd (int a, int b)
  4.     {
  5.         int temp;
  6.         while (b != 0) 
  7.         {
  8.             temp = a % b;
  9.             a = b;
  10.             b = temp;
  11.         }
  12.         return(a);
  13.     }
  14.     int main ()
  15.     {
  16.         int x = 15, y = 25;
  17.         cout << gcd(x, y);
  18.         return(0);
  19.     }

a) 15
b) 25
c) 375
d) 5

View Answer

Answer: d [Reason:] In this program, we are finding the gcd of the number. Output: $ g++ ret5.cpp $ a.out 5

Set 4

1. which keyword is used to define the macros in c++?
a) macro
b) define
c) #define
d) none of the mentioned

View Answer

Answer: c

2. Which symbol is used to declare the preprocessor directives?
a) #
b) $
c) *
d) ^

View Answer

Answer: a

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

View Answer

Answer: b [Reason:] There are two types of macros. They are object-like and function-like.

4. What is the mandatory preprosessor directive for c++?
a) #define <iostream>
b) #include <iostream>
c) #undef <iostream>
d) none of the mentioned

View Answer

Answer: b [Reason:] For a c++ program to execute, we need #include<iostream>.

5. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     #define MIN(a,b) (((a)<(b)) ? a : b)
  4.     int main ()
  5.     {
  6.         float i, j;
  7.         i = 100.1;
  8.         j = 100.01;
  9.         cout <<"The minimum is " << MIN(i, j) << endl;
  10.         return 0;
  11.     }

a) 100.01
b) 100.1
c) compile time error
d) none of the mentioned

View Answer

Answer: a [Reason:] In this program, we are getting the minimum number using conditional operator. Output: $ g++ mac3.cpp $ a.out The minimum value is 100.01

6. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     int main ()
  4.     {
  5.         cout << "Value of __LINE__ : " << __LINE__ << endl;
  6.         cout << "Value of __FILE__ : " << __FILE__ << endl;
  7.         cout << "Value of __DATE__ : " << __DATE__ << endl;
  8.         cout << "Value of __TIME__ : " << __TIME__ << endl;
  9.         return 0;
  10.     }

a) 5
b) details about your file
c) compile time error
d) none of the mentioned

View Answer

Answer: b [Reason:] In this program, we are using the macros to print the information about the file. Output: $ g++ mac2.cpp $ a.out Value of __LINE__ : 5 Value of __FILE__ : mac1.cpp Value of __DATE__ : Oct 10 2012 Value of __TIME__ : 22:24:37

7. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     #define SquareOf(x) x * x
  4.     int main()
  5.     {
  6.         int x;
  7.         cout << SquareOf(x + 4);
  8.         return 0;
  9.     }

a) 16
b) 64
c) compile time error
d) none of the mentioned

View Answer

Answer: d [Reason:] In this program, as we haven’t initiailzed the variable x, we will get a output of ending digit of 4. Output: $ g++ mac1.cpp $ a.out 75386824

8. What is the output of this program?

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

a) 10
b) 15
c) 20
d) none of the mentioned

View Answer

Answer: a [Reason:] In this program, we are just printing the declared values. Output: $ g++ mac.cpp $ a.out 10

9. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     #define MAX 10
  4.     int main()
  5.     {
  6.         int num;
  7.         num = ++MAX;
  8.         cout << num;
  9.         return 0;
  10.     }

a) 11
b) 10
c) compile time error
d) none of the mentioned

View Answer

Answer: c [Reason:] Macro Preprocessor only replaces occurance of macro symbol with macro symbol value, So we can’t increment the value.

10. What is the other name of the macro?
a) scripted directive
b) executed directive
c) link directive
d) none of the mentioned

View Answer

Answer: a [Reason:] When the compiler encounters a previously defined macro, it will take the result from that execution itself.

Set 5

1. The size of an object or a type can be determined using which operator?
a) malloc
b) sizeof
c) malloc
d) calloc

View Answer

Answer: b [Reason:] The sizeof operator gives the size of the object or type.

2. It is guaranteed that a ____ has atleast 8bits and a ____ has atleast 16 bits.
a) int, float
b) char, int
c) bool, char
d) char, short

View Answer

Answer: d

3. Implementation dependent aspects about an implementation can be found in ____
a) <implementation>
b) <limits>
c) <limit>
d) <numeric>

View Answer

Answer: b [Reason:] The limit header holds the details of the machine dependent details.

4. Size of C++ objects are expressed in terms of multiples of the size of a ____ and the size of a char is _______
a) char, 1
b) int, 1
c) float, 8
d) char, 4

View Answer

Answer: a

5. Identify the incorrect option.
a) 1 <= sizeof(bool) <= sizeof(long)
b) sizeof(float) <= sizeof(double) <= sizeof(long double)
c) sizeof(char) <= sizeof(long) <=sizeof(wchar_t)
d) sizeof(N) = sizeof(signed N) = sizeof(unsigned N)

View Answer

Answer: c [Reason:] sizeof(char) <= sizeof(wchar_t) <= sizeof(long).

6. What is the output of the following program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int num = 0x20 + 020 + 20;
  6.         cout << sizeof(num)<<'n';
  7.         return 0;
  8.     }

a) 2
b) 4
c) Depends on compiler
d) Garbage

View Answer

Answer: c [Reason:] The sum of three numbers are belongs to different number systems, so the result is typecasted into integer. Output: $ g++ size.cpp $ a.out 4

7. What is the output of the following program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     int main ( )
  4.     {
  5.         static double i;
  6.         i = 20;
  7.         cout << sizeof(i);
  8.         return 0;
  9.     }

a) 4
b) 2
c) 8
d) garbage

View Answer

Answer: c [Reason:] The size of the double data type is 8. $ g++ size1.cpp $ a.out 8

8. What is the output of the following program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int num1 = 10;
  6.         float num2 = 20;
  7.         cout << sizeof(num1 + num2);
  8.         return 0;
  9.     }

a) 2
b) 4
c) 8
d) garbage

View Answer

Answer: b [Reason:] In this program, integer is converted into float. Therefore the result of num1 and num2 is float. And it is returning the size of the float. Output: $ g++ size2.cpp $ a.out 4

9. What is the output of the following program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int a = 5;
  6.         float b;
  7.         cout << sizeof(++a + b);
  8.         cout << a;
  9.         return 0;
  10.     }

a) 2 6
b) 4 6
c) 2 5
d) 4 5

View Answer

Answer: d [Reason:] The a as a integer will be converted to float while calculating the size. The value of any variable doesn’t modify inside sizeof operator. Hence value of variable a will remain 5. Output: $ g++ size3.cpp $ a.out 4 5

10. What would be the output of the following program (in 32-bit systems)?

  1.     #include <iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         cout << sizeof(char);
  6.         cout << sizeof(int);
  7.         cout << sizeof(float);
  8.         return 0;
  9.     }

a) 1 4 4
b) 1 4 8
c) 1 8 8
d) none of the mentioned

View Answer

Answer: a [Reason:] Character is 1 byte, integer 4 bytes and float 4 bytes.

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