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 foo(int*);
  3.     int main()
  4.     {
  5.         int i = 10;
  6.         foo((&i)++);
  7.     }
  8.     void foo(int *p)
  9.     {
  10.         printf("%dn", *p);
  11.     }

a) 10
b) Some garbage value
c) Compile time error
d) Segmentation fault/code crash

View Answer

Answer: c

2. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void foo(int*);
  3.     int main()
  4.     {
  5.         int i = 10, *p = &i;
  6.         foo(p++);
  7.     }
  8.     void foo(int *p)
  9.     {
  10.         printf("%dn", *p);
  11.     }

a) 10
b) Some garbage value
c) Compile time error
d) Segmentation fault

View Answer

Answer: a

3. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void foo(float *);
  3.     int main()
  4.     {
  5.         int i = 10, *p = &i;
  6.         foo(&i);
  7.     }
  8.     void foo(float *p)
  9.     {
  10.         printf("%fn", *p);
  11.     }

a) 10.000000
b) 0.000000
c) Compile time error
d) Undefined behaviour

View Answer

Answer: b

4. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int i = 97, *p = &i;
  5.         foo(&i);
  6.         printf("%d ", *p);
  7.     }
  8.     void foo(int *p)
  9.     {
  10.         int j = 2;
  11.         p = &j;
  12.         printf("%d ", *p);
  13.     }

a) 2 97
b) 2 2
c) Compile time error
d) Segmentation fault/code crash

View Answer

Answer: a

5. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int i = 97, *p = &i;
  5.         foo(&p);
  6.         printf("%d ", *p);
  7.         return 0;
  8.     }
  9.     void foo(int **p)
  10.     {
  11.         int j = 2;
  12.         *p = &j;
  13.         printf("%d ", **p);
  14.     }

a) 2 2
b) 2 97
c) Undefined behaviour
d) Segmentation fault/code crash

View Answer

Answer: a

6. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int i = 11;
  5.         int *p = &i;
  6.         foo(&p);
  7.         printf("%d ", *p);
  8.     }
  9.     void foo(int *const *p)
  10.     {
  11.         int j = 10;
  12.         *p = &j;
  13.         printf("%d ", **p);
  14.     }

a) Compile time error
b) 10 10
c) Undefined behaviour
d) 10 11

View Answer

Answer: a

7. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int i = 10;
  5.         int *p = &i;
  6.         foo(&p);
  7.         printf("%d ", *p);
  8.         printf("%d ", *p);
  9.     }
  10.     void foo(int **const p)
  11.     {
  12.         int j = 11;
  13.         *p = &j;
  14.         printf("%d ", **p);
  15.     }

a) 11 11 11
b) 11 11 Undefined-value
c) Compile time error
d) Segmentation fault/code-crash

View Answer

Answer: b

8. What is the output of the code below?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int i = 10;
  5.         int *const p = &i;
  6.         foo(&p);
  7.         printf("%dn", *p);
  8.     }
  9.     void foo(int **p)
  10.     {
  11.         int j = 11;
  12.         *p = &j;
  13.         printf("%dn", **p);
  14.     }

a) 11 11
b) Undefined behaviour
c) Compile time error
d) Segmentation fault/code-crash

View Answer

Answer: a

9. Which of the following are correct syntaxes to send an array as a parameter to function:
a) func(&array);
b) func(#array);
c) func(*array);
d) func(array[size]);

View Answer

Answer: a

Set 2

1. What is the main feature of locale in C++?
a) Sustanability
b) Portability
c) Reliability
d) None of the mentioned

View Answer

Answer: b [Reason:] A locale is a set of features that are culture-specific, which can be used by programs to be more portable internationally.

2. Which objects information is loaded in locale object?
a) facet object
b) instead object
c) Both facet & instead object
d) None of the mentioned

View Answer

Answer: a [Reason:] A locale object contains information about which facet objects constitute a locale, and is each one of these facet objects that implements specific features as member functions.

3. How many categories are available in facets?
a) 4
b) 5
c) 6
d) 3

View Answer

Answer: c [Reason:] There are 6 categories of facet in c++. They are collate, ctype, monetary, numeric, time and messages.

4. What is the output of this program?

  1.     #include <stdio.h> 
  2.     #include <ctype.h>
  3.     int main ()
  4.     {
  5.         int i = 0;
  6.         char str[] = "Steve Jobsn";
  7.         char c;
  8.         while (str[i])
  9.         {
  10.             c = str[i];
  11.             if (islower(c)) 
  12.                 c = toupper(c);
  13.             putchar (c);
  14.             i++;
  15.         }
  16.         return 0;
  17.     }

a) Steve jobs
b) STEVE JOBS
c) Steve
d) None of the mentioned

View Answer

Answer: b [Reason:] In this program, We have converted the lower case letters to uppercase letters by using toupper function. Output: $ g++ loc.cpp $ a.out STEVE JOBS

5. What is the output of this program?

  1.     #include <stdio.h> 
  2.     #include <ctype.h>
  3.     int main ()
  4.     {
  5.         int i = 0;
  6.         char str[] = "C";
  7.         while (str[i])
  8.         {
  9.             if (isalpha(str[i])) 
  10.                 printf ("alphabetic");
  11.             else 
  12.                 printf ("not alphabetic");
  13.             i++;
  14.         }
  15.         return 0;
  16.     }

a) alphabetic
b) not alphabetic
c) Error
d) None of the mentioned

View Answer

Answer: a [Reason:] In this program, We are checking whether the character is alphabetic or not alphabetic by using the function isalpha. Output: $ g++ loc1.cpp $ a.out alphabetic

6. What is the output of this program?

  1.     #include <stdio.h>
  2.     #include <ctype.h>
  3.     int main ()
  4.     {
  5.         int i;
  6.         char str[] = "jobs...";
  7.         i = 0;
  8.         while ( isalnum(str[i] )) 
  9.             i++;
  10.         printf (" %dn",i);
  11.         return 0;
  12.     }

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

View Answer

Answer: d [Reason:] In this program, We are counting the number of alphanumeric values by using the function isalnum. Output: $ g++ loc2.cpp $ a.out 4

7. What is the output of this program?

  1.     #include <stdio.h>
  2.     #include <ctype.h>
  3.     int main ()
  4.     {
  5.         int i = 0;
  6.         int cx = 0;
  7.         char str[] = "Hello, welcome!";
  8.         while (str[i])
  9.         {
  10.             if (ispunct(str[i])) cx++;
  11.                 i++;
  12.         }    
  13.         printf ("%dn", cx);
  14.         return 0;
  15.     }

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

View Answer

Answer: b [Reason:] In this program, We are counting the number of special characters in the program by using the function ispunct. Output: $ g++ loc3.cpp $ a.out 2

8. What is the output of this program?

  1.     #include <stdio.h>
  2.     #include <stdlib.h>
  3.     #include <ctype.h>
  4.     int main ()
  5.     {
  6.         char str[] = "ffff";
  7.         long int number;
  8.         if (isxdigit(str[0]))
  9.         {
  10.             number = strtol (str, NULL, 16);
  11.             printf ("%ldn", number);
  12.         }
  13.         return 0;
  14.     }

a) 64345
b) 21312
c) 65535
d) Error

View Answer

Answer: c [Reason:] In this program, We are converting the hexadecimal number to decimal number. Output: $ g++ loc4.cpp $ a.out 65535

9. What kind of locale does every program is having in C++?
a) local locale
b) global locale
c) temp locale
d) none of the mentioned

View Answer

Answer: b [Reason:] Every program has a single locale object which is its global locale.

10. What will the monetary facet will do?
a) Handle formatting and parsing of monetary values
b) Handle formatting and parsing of character values
c) Parsing of character values
d) None of the mentioned

View Answer

Answer: a

Set 3

Here is a listing of tough C programming questions on “Goto & Labels” along with answers, explanations and/or solutions:

1. What is the output of the code given below?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         printf("%d ", 1);
  5.         goto l1;
  6.         printf("%d ", 2);
  7.         l1:goto l2;
  8.         printf("%d ", 3);
  9.         l2:printf("%d ", 4);
  10.    }

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

View Answer

Answer: a

2. What is the output of code given below?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         printf("%d ", 1);
  5.         l1:l2:
  6.         printf("%d ", 2);
  7.         printf("%dn", 3);
  8.     }

a) Compilation error
b) 1 2 3
c) 1 2
d) 1 3

View Answer

Answer: b

3. What is the output of code given below?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         printf("%d ", 1);
  5.         goto l1;
  6.         printf("%d ", 2);
  7.     }
  8.     void foo()
  9.     {
  10.         l1 : printf("3 ", 3);
  11.     }

a) 1 2 3
b) 1 3
c) 1 3 2
d) Compilation error

View Answer

Answer: d

4. What is output of code given below?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int i = 0, j = 0;
  5.         while (i < 2)
  6.         {
  7.             l1 : i++;
  8.             while (j < 3)
  9.             {
  10.                 printf("Loopn");
  11.                 goto l1;
  12.             }
  13.         }
  14.     }

a) Loop Loop
b) Compilation error
c) Loop Loop Loop Loop
d) Infinite Loop

View Answer

Answer: d

5. What is the output of code given below?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int i = 0, j = 0;
  5.         while (l1: i < 2)
  6.         {
  7.             i++;
  8.             while (j < 3)
  9.             {
  10.                 printf("loopn");
  11.                 goto l1;
  12.             }
  13.         }
  14.     }

a) loop loop
b) Compilation error
c) loop loop loop loop
d) Infinite loop

View Answer

Answer: b

6. What is the output of the code given below?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int i = 0, j = 0;
  5.         l1: while (i < 2)
  6.         {
  7.             i++;
  8.             while (j < 3)
  9.             {
  10.                 printf("loopn");
  11.                 goto l1;
  12.             }
  13.         }
  14.     }

a) loop loop
b) compilation error
c) oop loop loop loop
d) infinite loop

View Answer

Answer: a

7. The output of the code below is

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int i = 0;
  5.         if (i == 0)
  6.         {
  7.             goto label;
  8.         }
  9.         label: printf("Hello");
  10.     }

a) Nothing
b) Error
c) Infinite Hello
d) Hello

View Answer

Answer: d

8. The output of the code below is

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int i = 0, k;
  5.         if (i == 0)
  6.             goto label;
  7.             for (k = 0;k < 3; k++)
  8.             {
  9.                 printf("hin");
  10.                 label: k = printf("%03d", i);
  11.             }
  12.     }

a) 0
b) hi hi hi 0 0 0
c) 0 hi hi hi 0 0 0
d) 0 0 0

View Answer

Answer: a

9. The output of the code below is

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int i = 0, k;
  5.         label: printf("%d", i);
  6.         if (i == 0)
  7.             goto label;
  8.     }

a) 0
b) Infinite 0
c) Nothing
d) Error

View Answer

Answer: b

Set 4

Here is a listing of tough C++ programming questions on “Argument Passing” along with answers, explanations and/or solutions:

1. How many ways of passing a parameter are there in c++?
a) 1
b) 2
c) 3
d) 4

View Answer

Answer: c [Reason:] There are three ways of passing a parameter. They are pass by value,pass by reference and pass by pointer.

2. Which is used to keep the call by reference value as intact?
a) static
b) const
c) absolute
d) none of the mentioned

View Answer

Answer: b [Reason:] Because const will not change the value of the variables during the execution.

3. By default how the value are passed in c++?
a) call by value
b) call by reference
c) call by pointer
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 copy (int& a, int& b, int& c)
  4.     {
  5.         a *= 2;
  6.         b *= 2;
  7.         c *= 2;
  8.     }
  9.     int main ()
  10.     {
  11.         int x = 1, y = 3, z = 7;
  12.         copy (x, y, z);
  13.         cout << "x =" << x << ", y =" << y << ", z =" << z;
  14.         return 0;
  15.     }

a) 2 5 10
b) 2 4 5
c) 2 6 14
d) none of the mentioned

View Answer

Answer: c [Reason:] Because we multiplied the values by 2 in the copy function. Output: $ g++ arg6.cpp $ a.out x = 2,y = 6,z = 14

5. What is the new value of x?

  1.     #include <iostream>
  2.     using namespace std;
  3.     void fun(int &x)
  4.     {
  5.         x = 20;
  6.     }
  7.     int main()
  8.     {
  9.          int x = 10;
  10.          fun(x);
  11.          cout << "New value of x is " << x;
  12.          return 0;
  13.     }

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

View Answer

Answer: b [Reason:] As we passed by reference, the value is changed and it is returned as 20. Output: $ g++ arg5.cpp $ a.out 20

6. 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

7. 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

8. 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

9. 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 any 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.

10. 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 5

Here is a listing of tough C++ programming questions on “Min and Max” along with answers, explanations and/or solutions:

1. Which keyword is used to declare the min and max functions?
a) iostream
b) string
c) algorithm
d) none of the mentioned

View Answer

Answer: c [Reason:] Algorithm header file contain the supporting files needed for the execution of these functions.

2. What kind of functions are min and max in c++?
a) Type specific
b) Variable specific
c) Type & Variable specific
d) None of the mentioned

View Answer

Answer: a [Reason:] The min/max functions are type specific but they will not force everything to be converted to/from floating point. The functions that will force everything to be converted to/from floating point are fmin/fmax.

3. How many parameters are needed for minmax function?
a) 1
b) 2
c) 3
d) All of the mentioned

View Answer

Answer: d [Reason:] The “minmax” function can take the following: 1 parameter: An initializer_list object. 2 parameters: Values to compare. 2 parameters: An initializer_list object.and comparaison function 3 parameters: Values to compare.and comparaison function

4. What is the output of this program?

  1.     #include <iostream>   
  2.     #include <algorithm>  
  3.     using namespace std;
  4.     int main () 
  5.     {
  6.         cout << "max(1, 2) == " << max(1, 2) << 'n';
  7.         cout << "max('a', 'z') == " << max('a', 'z') << 'n';
  8.         return 0;
  9.     }

a) 2z
b) 2a
c) Error
d) None of the mentioned

View Answer

Answer: a [Reason:] In this program, We found the max value in the given value by using max function. Output: $ g++ max.cpp $ a.out max(1, 2) == 2 max(‘a’, ‘z’) == z

5. What is the output of this program?

  1.     #include <iostream>
  2.     #include <algorithm>
  3.     using namespace std;
  4.     bool myfn(int i, int j) 
  5.     {
  6.         return i < j;
  7.     }
  8.     int main () 
  9.     {
  10.         int myints[ ] = {3, 7, 2, 5, 6, 4, 9};
  11.         cout <<  *min_element(myints, myints + 7, myfn) << 'n';
  12.         cout << *max_element(myints, myints + 7, myfn) << 'n';
  13.         return 0;
  14.     }

a) 2 9
b) 2 7
c) 3 9
d) 3 5

View Answer

Answer: a [Reason:] In this program, We found out the minimum value and maximum value of a range. Output: $ g++ max1.cpp $ a.out 2 9

6. What is the output of this program?

  1.     #include <iostream>
  2.     #include <algorithm>
  3.     #include <vector>
  4.     using namespace std;
  5.     int main () 
  6.     {
  7.         int myints[] = {10, 20, 30, 30, 20, 10, 10, 20};
  8.         vector<int> v(myints, myints + 8);
  9.         sort (v.begin(), v.end());
  10.         vector<int> :: iterator low, up;
  11.         low = lower_bound (v.begin(), v.end(), 20);
  12.         up = upper_bound (v.begin(), v.end(), 20);
  13.         cout << (low - v.begin()) << ' ';
  14.         cout << (up - v.begin()) << 'n';
  15.         return 0;
  16.     }

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

View Answer

Answer: a [Reason:] In this program, We are finding the upper bound and lower bound values by using lower_bound and upper_bound methods. Output: $ g++ max2.cpp $ a.out 3 6

7. What is the output of this program?

  1.     #include <iostream>
  2.     #include <algorithm>
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         cout << min(2, 1) << ' ';
  7.         cout << min('m','m') << 'n';
  8.         return 0;
  9.     }

a) Error
b) Runtime error
c) 1 m
d) None of the mentioned

View Answer

Answer: c [Reason:] In this program, We are finding the minimum value by using min method. Output: $ g++ max3.cpp $ a.out 1 m

8. What is the output of this program?

  1.     #include <iostream>
  2.     #include <algorithm>
  3.     #include <vector>
  4.     using namespace std;
  5.     bool mygreater (int i,int j) 
  6.     {
  7.         return (i > j);
  8.     }
  9.     int main () 
  10.     {
  11.         int myints[] = {10, 20, 30, 30, 20, 10, 10, 20};
  12.         vector<int> v(myints, myints + 8);
  13.         pair<vector<int> :: iterator, vector<int> :: iterator> bounds;
  14.         sort (v.begin(), v.end());
  15.         bounds = equal_range (v.begin(), v.end(), 20);
  16.         cout  << (bounds.first - v.begin());
  17.         cout << " and " << (bounds.second - v.begin()) << 'n';
  18.         return 0;
  19.     }

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

View Answer

Answer: a [Reason:] In this program, We are finding out the equal range in the vector. Output: $ g++ max4.cpp $ a.out 3 and 6

9. Which function is used to return the minimum element in the range?
a) min
b) minimum
c) min_element
d) none of the mentioned

View Answer

Answer: c [Reason:] The min_element is used to compare the range of elements and it can find out the minimum element.

10. Which operator is used to compare the values to find min and max?
a) <
b) >
c) <<
d) >>

View Answer

Answer: a