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. which of the following is used to implement the c++ interfaces?
a) absolute variables
b) abstract classes
c) constant variables
d) none of the mentioned

View Answer

Answer: b

2. What is the ability to group some lines of code that can be included
in the program?
a) specific task
b) program control
c) modularization
d) macros

View Answer

Answer: c [Reason:] Modularization is also similar to macros but it is used to build large projects.

3. How many types does functions fall depends on modularization?
a) 1
b) 2
c) 3
d) 4

View Answer

Answer: b [Reason:] There are two types of functions.They are program control and specific task.

4. How many types of modularization are there in c++?
a) 4
b) 3
C) 1
d) none of the mentioned

View Answer

Answer: d [Reason:] There are two types of modular programming.They are interface and implementation.

5. What does the client module import?
a) macro
b) records
c) interface
d) none of the mentioned

View Answer

Answer: c [Reason:] Because they access the functions in the module using interface.

6. Identify the correct statement.
a) c++ does not have built-in interfaces
b) c++ does have built-in interfaces
c) c++ have no cocept of interfaces
d) none of the mentioned

View Answer

Answer: a

7. What is similar to interface in c++
a) methods
b) instance of class
c) pure abstract class
d) none of the mentioned

View Answer

Answer: c

8. Which of the following implements the module in the program?
a) macro
b) header files
c) macro& header files
d) none of the mentioned

View Answer

Answer: b [Reason:] We can include the group of code by using the #include header file.

Set 2

Here is a listing of online C++ quiz on “String Class” along with answers, explanations and/or solutions:

1. How many types of representation are in string?
a) 1
b) 2
c) 3
d) 4

View Answer

Answer: b [Reason:] C++ provides following two types of string representations. They are C-style character string and string class type with Standard C++.

2. What is the header file for the string class?

a) #include<ios>
b) #include<str>
c) #include<string>
d) None of the mentioned

View Answer

Answer: c

3. Which is used to return the number of characters in the string?
a) length
b) size
c) both size & length
d) none of the mentioned

View Answer

Answer: c [Reason:] Both will return the number of characters that conform the string’s content.

4. What is the output of this program?

  1.     #include <iostream>
  2.     #include <cstring>
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         char str1[10] = "Hello";
  7.         char str2[10] = "World";
  8.         char str3[10];
  9.         int  len ;
  10.         strcpy( str3, str1);
  11.         strcat( str1, str2)
  12.         len = strlen(str1);
  13.         cout << len << endl;
  14.         return 0;
  15.     }

a) 5
b) 55
c) 11
d) 10

View Answer

Answer: d [Reason:] In the program, We are concatanating the str1 and str2 and printing it’s total length. So the length is 10. Output: $ g++ stri.cpp $ a.out 10

5. What is the output of this program?

  1.     #include <iostream>
  2.     #include <string>
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         string str ("microsoft");
  7.         string::reverse_iterator r;
  8.         for (r = str.rbegin() ; r < str.rend(); r++ )
  9.             cout << *r;
  10.         return 0;
  11.     }

a) microsoft
b) micro
c) tfosorcim
d) tfos

View Answer

Answer: c [Reason:] ‘rbegin’ is used to reverse the given the string. Output: $ g++ stri1.cpp $ a.out tfosorcim

6. What is the output of this program?

  1.    #include <iostream>
  2.    #include <string>
  3.    using namespace std;
  4.    int main ()
  5.    {
  6.        string str ("nobody does like this");
  7.        string key ("nobody");
  8.        size_t f;
  9.        f = str.rfind(key);
  10.        if (f != string::npos)
  11.            str.replace (f, key.length(), "everybody");
  12.        cout << str << endl;
  13.        return 0;
  14.    }

a) nobody does like this
b) nobody
c) everybody
d) everybody does like this

View Answer

Answer: d [Reason:] rfind is used to find the characters in the string and replace is used to replace with certain characters. Output: $ g++ stri2.cpp $ a.out everbody does like this

7. What is the output of this program?

  1.     #include <iostream>
  2.     #include <string>
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         string str ("steve jobs is legend");
  7.         string::iterator it;
  8.         str.erase (str.begin()+ 5, str.end()-7);
  9.         cout << str << endl;      
  10.         return 0;
  11.     }

a) jobs is
b) steve legend
c) steve
d) none of the mentioned

View Answer

Answer: b [Reason:] In this program, We are leaving the first 5 characters and last 7 characters and we are erasing the remaining the characters. Output: $ g++ stri3.cpp $ a.out steve legend

8. What is the output of this program?

  1.     #include <iostream>
  2.     #include <string>
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         string str ("Microsoft");
  7.         for (size_t i = 0; i < str.length();)
  8.         {
  9.             cout << str.at(i-1);
  10.         }
  11.         return 0;
  12.     }

a) M
b) Microsoft
c) Micro
d) runtime error

View Answer

Answer: d [Reason:] This program will terminate because the cout element is out of range.

9. What is the output of this program?

  1.    #include <iostream>
  2.    #include <string>
  3.    using namespace std;
  4.    int main ()
  5.    {
  6.        string str ("Ubuntu");
  7.        cout << str.capacity();
  8.        cout << str.max_size();
  9.        return 0;
  10.    }

a) 61073741820
b) 51073741820
c) 6 and max size depends on compiler
d) none of the mentioned

View Answer

Answer: c [Reason:] In this program, We are printing the capacity and max size of the string. Output: $ g++ stri5.cpp $ a.out 61073741820

10. Which method do we use to append more than one character at a time?
a) append
b) operator+=
c) data
d) both append & operator+=

View Answer

Answer: d

Set 3

1. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int i;
  3.     int main()
  4.     {
  5.         extern int i;
  6.         if (i == 0)
  7.             printf("scope rulesn");
  8.     }

a) scope rules
b) Compile time error due to multiple declaration
c) Compile time error due to not defining type in statement extern i
d) Nothing as i value is not zero being automatic variable

View Answer

Answer: a

2. What is the output of this C code (without linking the source file in which ary1 is defined)?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         extern ary1[];
  5.         printf("scope rulesn");
  6.     }

a) scope rules
b) Linking error due to undefined reference
c) Compile time error because size of array is not provided
d) Compile time error because datatype of array is not provided

View Answer

Answer: a

3. What is the output of this C code after linking with source file having definition of ary1?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         extern ary1[];
  5.         printf("%dn", ary1[0]);
  6.     }

a) Value of ary1[0]

b) Compile time error due to multiple definition
c) Compile time error because size of array is not provided
d) Compile time error because datatype of array is not provided

View Answer

Answer: d

4. What is the scope of an external variable?
a) Whole source file in which it is defined
b) From the point of declaration to the end of the file in which it is defined
c) Any source file in a program
d) From the point of declaration to the end of the file being compiled

View Answer

Answer: d

5. What is the scope of a function?
a) Whole source file in which it is defined
b) From the point of declaration to the end of the file in which it is defined
c) Any source file in a program
d) From the point of declaration to the end of the file being compiled

View Answer

Answer: d

6. Comment on the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int i;
  5.         for (i = 0;i < 5; i++)
  6.         int a = i;
  7.         printf("%d", a);
  8.     }

a) a is out of scope when printf is called
b) Redeclaration of a in same scope throws error
c) Syntax error in declaration of a
d) No errors, program will show the output 5

View Answer

Answer: c

7. Which variable has the longest scope?

  1.     #include <stdio.h>
  2.     int b;
  3.     int main()
  4.     {
  5.         int c;
  6.         return 0;
  7.     }
  8.     int a;

a) a
b) b
c) c
d) Both a and b

View Answer

Answer: b

8. Comment on the output of this 2 C code?

  1.     #include <stdio.h> //Program 1
  2.     int main()
  3.     {
  4.         int a;
  5.         int b;
  6.         int c;
  7.     }
  8.  
  9.     #include <stdio.h> //Program 2
  10.     int main()
  11.     {
  12.         int a;
  13.         {
  14.             int b;
  15.         }
  16.         {
  17.             int c;
  18.         }
  19.     }

a) They are both the same
b) Scope of C is till the end of program
c) All operation in Program 1 can also be performed in Program 2
d) None of the mentioned

View Answer

Answer: c

Set 4

1. The scope of an automatic variable is:
a) Within the block it appears
b) Within the blocks of the block it appears
c) Until the end of program
d) Within the block it appears & Within the blocks of the block it appears

View Answer

Answer: d

2. Automatic variables are allocated space in the form of a:
a) stack
b) queue
c) priority queue
d) random

View Answer

Answer: a

3. Which of the following is a storage specifier?
a) enum
b) union
c) auto
d) volatile

View Answer

Answer: c

4. Default storage class if not any is specified for a local variable, is auto
a) true
b) false
c) Depends on the standard
d) None of the mentioned

View Answer

Answer: a

5. What is the output of this C code?

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

a) 10
b) Compile time error
c) Depends on the standard
d) None of the mentioned

View Answer

Answer: b

6. Automatic variables are stored in
a) stack
b) data segment
c) register
d) heap

View Answer

Answer: a

7. What linkage does automatic variables have?
a) Internal linkage
b) External linkage
c) No linkage
d) None of the mentioned

View Answer

Answer: c

8. What is the output of this C code?

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

a) 10
b) Compile time error
c) Depends on the standard
d) Depends on the compiler

View Answer

Answer: a

Set 5

Here is a listing of online C quiz on “Basics of Structures” along with answers, explanations and/or solutions:

1. Which of the following are themselves a collection of different data types?
a) string
b) structures
c) char
d) all of the mentioned

View Answer

Answer: b

2. User-defined data type can be derived by___________
a) struct
b) enum
c) typedef
d) all of the mentioned

View Answer

Answer: d

3. Which operator connects the structure name to its member name?
a) –
b) <-
c) .
d) Both <- and .

View Answer

Answer: c

4. Which of the following cannot be a structure member?
a) Another structure
b) Function
c) Array
d) None of the mentioned

View Answer

Answer: b

5. Which of the following structure declaration will throw an error?
a) struct temp{}s;
    main(){}
b) struct temp{};
    struct temp s;
    main(){}
c) struct temp s;
    struct temp{};
    main(){}
d) None of the mentioned

View Answer

Answer: d

6. What is the output of this C code?

  1.     #include <stdio.h>
  2.     struct student
  3.     {
  4.         int no;
  5.         char name[20];
  6.     }
  7.     void main()
  8.     {
  9.         struct student s;
  10.         s.no = 8;
  11.         printf("hello");
  12.     }

a) Compile time error
b) Nothing
c) hello
d) Varies

View Answer

Answer: a

7. What is the output of this C code?

  1.     #include <stdio.h>
  2.     struct student
  3.     {
  4.         int no = 5;
  5.         char name[20];
  6.     };
  7.     void main()
  8.     {
  9.         struct student s;
  10.         s.no = 8;
  11.         printf("hello");
  12.     }

a) Nothing
b) Compile time error
c) hello
d) Varies

View Answer

Answer: b

8. What is the output of this C code?

  1.     #include <stdio.h>
  2.     struct student
  3.     {
  4.         int no;
  5.         char name[20];
  6.     };
  7.     void main()
  8.     {
  9.         student s;
  10.         s.no = 8;
  11.         printf("hello");
  12.     }

a) Nothing
b) hello
c) Compile time error
d) Varies

View Answer

Answer: c

9. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         struct student
  5.         {
  6.             int no;
  7.             char name[20];
  8.         };
  9.         struct student s;
  10.         s.no = 8;
  11.         printf("%d", s.no);
  12.     }

a) Nothing
b) Compile time error
c) Junk
d) 8

View Answer

Answer: d

10. Can the above code be compiled successfully?

  1.     #include <stdio.h>
  2.     struct p
  3.     {
  4.         int k;
  5.         char c;
  6.         float f;
  7.     };
  8.     int main()
  9.     {
  10.         struct p x = {.c = 97, .f = 3, .k = 1};
  11.         printf("%fn", x.f);
  12.     }

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

View Answer

Answer: c