Test Your Coding Skills: Trivia Quiz!

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Code_Quest_2k18
C
Code_Quest_2k18
Community Contributor
Quizzes Created: 1 | Total Attempts: 448
Questions: 30 | Attempts: 448

SettingsSettingsSettings
Test Your Coding Skills: Trivia Quiz! - Quiz

.


Questions and Answers
  • 1. 

    What will happen if the below program is executed? #include  int main()  int main =3;  printf("%d", main);  return 0;  }

    • A.

      It will cause a compile-time error

    • B.

      It will cause a run-time error

    • C.

      It will run without any error and prints 3

    • D.

      It will experience infinite looping

    Correct Answer
    C. It will run without any error and prints 3
    Explanation
    The program will run without any error and print the value 3. This is because the variable "main" is declared as an integer and assigned the value 3. The printf statement then prints the value of "main", which is 3. There are no syntax errors or logical errors in the code, so it will execute successfully.

    Rate this question:

  • 2. 

    Which of the following cannot be a variable name in c?

    • A.

      Volatile

    • B.

      True

    • C.

      Friend

    • D.

      Export

    Correct Answer
    A. Volatile
    Explanation
    In C, "Volatile" cannot be a variable name because it is a reserved keyword. Reserved keywords are predefined words that have special meanings in the programming language and cannot be used as variable names. "True", "Friend", and "Export" can all be variable names in C.

    Rate this question:

  • 3. 

    The maximum number of arguments that can be passed in a single function are_________________

    • A.

      127

    • B.

      253

    • C.

      361

    • D.

      No limits in number of arguments

    Correct Answer
    B. 253
    Explanation
    The correct answer is 253. In most programming languages, including C and C++, the maximum number of arguments that can be passed in a single function is limited by the size of the stack. The stack is a limited amount of memory allocated for each function call, and it is used to store local variables and function arguments. The size of the stack determines the maximum number of arguments that can be passed. In many systems, the default stack size is 8 MB, and each argument typically takes up 4 bytes of memory. Therefore, the maximum number of arguments would be 8 MB / 4 bytes = 2,097,152 arguments. However, some memory is also needed for other purposes, so the practical limit is usually lower. In this case, the correct answer is 253, which is a reasonable limit for most practical purposes.

    Rate this question:

  • 4. 

    User-defined data type can be derived by_____________

    • A.

      Struct

    • B.

      Enum

    • C.

      Typedef

    • D.

      All of the mentioned

    Correct Answer
    D. All of the mentioned
    Explanation
    User-defined data types can be derived by using any of the mentioned options, which are struct, enum, and typedef.

    - A struct allows the user to create a composite data type by combining different data types into a single entity.
    - An enum allows the user to define a set of named values, which can be used to represent a set of related constants.
    - The typedef keyword allows the user to create an alias or a new name for an existing data type, making it easier to use and understand in the code.

    Therefore, all of the mentioned options can be used to derive user-defined data types.

    Rate this question:

  • 5. 

    Size of a union is determined by size of the.

    • A.

      First member in the union

    • B.

      Last member in the union

    • C.

      Biggest member in the union

    • D.

      Sum of the sizes of all members

    Correct Answer
    C. Biggest member in the union
    Explanation
    The size of a union is determined by the biggest member in the union because a union allocates enough memory to hold the largest member among its members. This ensures that the union can accommodate any of its members without wasting unnecessary memory. Therefore, the size of a union is equal to the size of its largest member.

    Rate this question:

  • 6. 

    Members of a union are accessed as________________

    • A.

      Union-name.member

    • B.

      Union-pointer->member

    • C.

      Both union-name.member& union-pointer->member

    • D.

      None of the above mentioned

    Correct Answer
    C. Both union-name.member& union-pointer->member
    Explanation
    Both union-name.member and union-pointer->member are correct ways to access members of a union. The dot operator (union-name.member) is used when accessing the members of a union directly using the union name. The arrow operator (union-pointer->member) is used when accessing the members of a union through a pointer to the union.

    Rate this question:

  • 7. 

    What type of array is generally generated in command-line argument?

    • A.

      Single dimension array

    • B.

      2-dimensional square array

    • C.

      Jagged array

    • D.

      2-dimensional rectangular array

    Correct Answer
    C. Jagged array
    Explanation
    A jagged array is a type of array that contains other arrays as its elements. Each of these arrays can have a different length, allowing for more flexibility in storing data. In the context of command-line arguments, a jagged array is often used to store multiple arguments, where each argument is represented by a separate array. This allows for easy access and manipulation of the arguments within the program. Therefore, a jagged array is generally generated in command-line arguments.

    Rate this question:

  • 8. 

    Operation “a = a * b + a” can also be written as :

    • A.

      A *= b + 1;

    • B.

      (c = a * b)!=(a = c + a);

    • C.

      A = (b + 1)* a;

    • D.

      All of the above

    Correct Answer
    D. All of the above
    Explanation
    The given operation "a = a * b + a" can be written in multiple ways. The first option "a *= b + 1" is equivalent to "a = a * (b + 1)". The second option "(c = a * b) != (a = c + a)" assigns the product of a and b to c, then checks if c is not equal to the sum of c and a, and assigns the result to a. The third option "a = (b + 1) * a" is equivalent to "a = a * (b + 1)". Therefore, all of the above options are correct ways to write the given operation.

    Rate this question:

  • 9. 

    The following expression can be substituted for.     if (isalpha(c) && isdigit(c))

    • A.

      If (isalnum(c))

    • B.

      If (isalphanum(c))

    • C.

      If (isalphanumeric(c))

    • D.

      None of the above

    Correct Answer
    D. None of the above
  • 10. 

    C++ exception handling mechanism mainly uses how many keywords?

    • A.

      Four

    • B.

      Three

    • C.

      Two

    • D.

      None of the above

    Correct Answer
    B. Three
    Explanation
    The correct answer is three because C++ exception handling mechanism mainly uses three keywords: try, catch, and throw. The try block is used to enclose the code that may throw an exception, the catch block is used to handle the thrown exception, and the throw keyword is used to explicitly throw an exception. These three keywords are essential for implementing exception handling in C++.

    Rate this question:

  • 11. 

    After defining the function template, the next step to call it in another function such as ______________

    • A.

      Int()

    • B.

      Secondary()

    • C.

      Template()

    • D.

      Main()

    Correct Answer
    D. Main()
    Explanation
    After defining the function template, the next step is to call it in another function such as "main()". The "main()" function is the entry point of a C++ program, and it is where the program execution begins. Therefore, calling the function template in "main()" allows the program to utilize and execute the template code.

    Rate this question:

  • 12. 

    Runtime polymorphism is achieved by____________

    • A.

      Friend function

    • B.

      Virtual function

    • C.

      Operator overloading

    • D.

      Function overloading

    Correct Answer
    B. Virtual function
    Explanation
    Runtime polymorphism is achieved by using virtual functions. Virtual functions allow a derived class to override the implementation of a base class function. This means that when a function is called using a base class pointer or reference, the actual implementation of the function in the derived class is executed at runtime. This enables dynamic dispatch, where the appropriate function implementation is determined based on the type of the object being pointed to or referenced. By using virtual functions, different objects of the same base class can exhibit different behaviors, leading to polymorphism.

    Rate this question:

  • 13. 

    Which of the following is/are the new cast operators used in c++.
    1. const_cast
    2. static_cast
    3. dynamic_cast
    4. new_cast

    • A.

      1, 2 and 3 only

    • B.

      2, 3 and 4 only

    • C.

      1, 3 and 4 only

    • D.

      All 1, 2, 3 and 4

    Correct Answer
    A. 1, 2 and 3 only
    Explanation
    The correct answer is 1, 2 and 3 only. These are the new cast operators used in C++. The const_cast is used to cast away the constness of a variable, static_cast is used for general type conversions, and dynamic_cast is used for safe downcasting and cross-casting between classes with virtual functions. The new_cast is not a valid cast operator in C++.

    Rate this question:

  • 14. 

    Which of the following statements about member functions are true or false.
    1. A member function can call another member function directly with using the dot operator.
    2. Member function can access  the private data of the class.

    • A.

      1 - true, 2 - true

    • B.

      1 - false, 2 - true

    • C.

      1 - true, 2 - false

    • D.

      1 - true, 2 - true

    Correct Answer
    B. 1 - false, 2 - true
    Explanation
    The first statement is false because a member function can call another member function directly using the dot operator. The second statement is true because member functions can access the private data of the class they belong to.

    Rate this question:

  • 15. 

    Static variables are like ___________ as they are declared in a class declaration and defined in the source file.

    • A.

      Inline member function

    • B.

      Non-inline member function

    • C.

      Static member function

    • D.

      Dynamic member function

    Correct Answer
    B. Non-inline member function
    Explanation
    Static variables are like non-inline member functions as they are declared in a class declaration and defined in the source file. Non-inline member functions are defined outside the class declaration and can be accessed using the scope resolution operator (::). Similarly, static variables are also defined outside the class declaration and can be accessed using the scope resolution operator.

    Rate this question:

  • 16. 

    Which statement gets affected when i++ is changed to ++i?

    • A.

      I = 20; i++;

    • B.

      For (i = 0; i

    • C.

      A = i++;

    • D.

      While (i++ = 20) cout

    Correct Answer
    A. I = 20; i++;
    Explanation
    Changing i++ to ++i in the given code will affect the statement "a = i++;". With i++ as the post-increment operator, the value of i will be assigned to a and then incremented by 1. However, if we change it to ++i, the value of i will be incremented by 1 first and then assigned to a. Therefore, the value of a will be different depending on whether we use i++ or ++i.

    Rate this question:

  • 17. 

    If a program uses inline function, then the function is expanded inline at ____________

    • A.

      Compile time

    • B.

      Run time

    • C.

      Both A and B

    • D.

      None of the above

    Correct Answer
    B. Run time
    Explanation
    When a program uses an inline function, the function is expanded inline at run time. This means that instead of the function call, the actual code of the function is inserted at the location where the function is called. This can lead to faster execution as it eliminates the overhead of a function call. However, this expansion happens at run time, not at compile time. Therefore, the correct answer is run time.

    Rate this question:

  • 18. 

    If an argument to a function is declared as const, then

    • A.

      Function can modify the argument

    • B.

      Function can’t modify the argument

    • C.

      Const argument to a function is not possible

    • D.

      None of the above

    Correct Answer
    B. Function can’t modify the argument
    Explanation
    If an argument to a function is declared as const, it means that the function is not allowed to modify the argument. The const keyword indicates that the value of the argument should remain unchanged throughout the function. This is useful when we want to ensure that a function does not accidentally modify the argument and helps in maintaining the integrity of the data.

    Rate this question:

  • 19. 

    Which cause a compiler error?

    • A.

      Int[ ] scores = {3, 5, 7};

    • B.

      Int [ ][ ] scores = {2,7,6}, {9,3,45};

    • C.

      String cats[ ] = {"fluffy", "spot", "zeus"};

    • D.

      Boolean results[ ] = new boolean [] {true, false, true};

    • E.

      Integer results[ ] = {new integer(3), new integer(5), new integer(8)};

    Correct Answer
    B. Int [ ][ ] scores = {2,7,6}, {9,3,45};
    Explanation
    The given line of code "int [ ][ ] scores = {2,7,6}, {9,3,45};" causes a compiler error because the array initializer is not properly formatted. In a 2D array, each row should be enclosed in curly braces, but in this case, the second row is not enclosed correctly. To fix the error, the code should be written as "int [ ][ ] scores = {{2,7,6}, {9,3,45}};".

    Rate this question:

  • 20. 

    Which interface provides the capability to store objects using a key-value pair?

    • A.

      Java.util.map

    • B.

      Java.util.set

    • C.

      Java.util.list

    • D.

      Java.util.collection

    Correct Answer
    D. Java.util.collection
    Explanation
    The correct answer is java.util.map. The java.util.map interface provides the capability to store objects using a key-value pair. It allows you to associate a value with a unique key and retrieve the value using that key. The map interface is commonly used to implement data structures such as hash tables and dictionaries.

    Rate this question:

  • 21. 

    public class myfile   {     public static void main (string[] args)     {         string biz = args[1];         string baz = args[2];         string rip = args[3];         System.out.println("arg is " + rip);     }   } Select how you would start the program to cause it to print: arg is 2

    • A.

      Java myfile 222

    • B.

      Java myfile 1 2 2 3 4

    • C.

      Java myfile 1 3 2 2

    • D.

      Java myfile 0 1 2 3

    Correct Answer
    C. Java myfile 1 3 2 2
    Explanation
    The program takes command line arguments and assigns them to variables biz, baz, and rip. The program then prints the value of the rip variable. In order to cause it to print "arg is 2", the command line arguments should be "java myfile 1 3 2 2".

    Rate this question:

  • 22. 

    What will be the output of the program? public class arraytest   {     public static void main(string[ ] args)     {         float f1[ ], f2[ ];         f1 = new float[10];         f2 = f1;         System.out.println("f2[0] = " + f2[0]);     }   }

    • A.

      It prints f2[0] = 0.0

    • B.

      It prints f2[0] = nan

    • C.

      An error at f2 = f1; causes compile to fail.

    • D.

      It prints the garbage value.

    Correct Answer
    B. It prints f2[0] = nan
    Explanation
    The program creates two float arrays, f1 and f2, with a size of 10. The reference variable f2 is then assigned to the same memory location as f1. Since f1 is a newly created array, all of its elements are initialized to the default value of 0.0. Therefore, when accessing f2[0], which points to the same memory location as f1[0], the output will be 0.0.

    Rate this question:

  • 23. 

    What is the output of the following program? public class Test {     public static void main(String[] args)     {         double data = 444.324;         int sum = 9;         float value = 5.1f;         System.out.println(data + sum + value);               } }

    • A.

      444.32495.1

    • B.

      456

    • C.

      458.42399

    • D.

      458.4

    Correct Answer
    C. 458.42399
    Explanation
    The program first adds the double variable "data" and the integer variable "sum", resulting in 453.324. Then, it adds the float variable "value" to the previous result, resulting in 458.42399. This value is then printed as the output.

    Rate this question:

  • 24. 

    What will be the output of the program? public class test  {     private static int[] x;     public static void main(string[] args)     {         system.out.println(x[0]);     }  }

    • A.

      0

    • B.

      Null

    • C.

      Compile error

    • D.

      Nullpointerexception at runtime

    Correct Answer
    D. Nullpointerexception at runtime
    Explanation
    The program will throw a NullPointerException at runtime because the array "x" is declared but not initialized. Therefore, when trying to access the first element of the array (x[0]), it will throw a NullPointerException.

    Rate this question:

  • 25. 

    What will be the output :   int i=25;   byte b=(byte)i;   System.out.println(b);

    • A.

      255

    • B.

      -1

    • C.

      -255

    • D.

      -127

    Correct Answer
    B. -1
    Explanation
    The output will be -1. In this code, the integer value 25 is assigned to the variable 'i'. Then, the value of 'i' is explicitly casted to a byte data type and assigned to the variable 'b'. The byte data type can hold values from -128 to 127. Since 25 is within this range, the value remains the same. However, when the value of 'b' is printed using System.out.println, it is displayed as -1 because the byte data type is signed and the most significant bit is interpreted as a sign bit.

    Rate this question:

  • 26. 

    What is the time complexity of inserting a node in a doubly linked list?

    • A.

      O(nlogn)

    • B.

      O(logn)

    • C.

      O(n)

    • D.

      O(1)

    Correct Answer
    D. O(1)
    Explanation
    The time complexity of inserting a node in a doubly linked list is O(1). This is because in a doubly linked list, each node contains references to both the previous and the next node. Therefore, when inserting a new node, we only need to update the references of the new node and its adjacent nodes, which can be done in constant time regardless of the size of the list.

    Rate this question:

  • 27. 

    With what data structure can a priority queue be implemented ?

    • A.

      Array

    • B.

      List

    • C.

      Heap

    • D.

      All of above

    Correct Answer
    D. All of above
    Explanation
    A priority queue can be implemented using any of the given data structures: Array, List, or Heap.
    - An array can be used to implement a priority queue by storing the elements in a linear structure and maintaining their priority order.
    - A list can also be used by keeping the elements in a linked structure and sorting them based on their priority.
    - A heap is a specialized tree-based data structure that can efficiently implement a priority queue by maintaining the highest priority element at the root.
    Therefore, all of the above data structures can be used to implement a priority queue.

    Rate this question:

  • 28. 

    What is the maximum possible number of edges in a directed graph with no self loops having 8 vertices?

    • A.

      28

    • B.

      64

    • C.

      256

    • D.

      56

    Correct Answer
    D. 56
    Explanation
    The maximum possible number of edges in a directed graph with no self loops can be calculated using the formula n(n-1), where n is the number of vertices. In this case, with 8 vertices, the maximum possible number of edges would be 8(8-1) = 56.

    Rate this question:

  • 29. 

    The given array is arr = {2,6,1}. What are the pivots that are returned as a result of subsequent partitioning?

    • A.

      1 and 6

    • B.

      6 and 1

    • C.

      2 and 6

    • D.

      None of the above mentioned

    Correct Answer
    D. None of the above mentioned
    Explanation
    The given array {2,6,1} does not have any pivots as a result of subsequent partitioning. In order to have a pivot, the array needs to be partitioned around a specific element. However, in this case, the array is not being partitioned, so there are no pivots returned.

    Rate this question:

  • 30. 

    Which of the following application makes use of a circular linked list?

    • A.

      Undo operation in a text editor

    • B.

      Recursive function calls

    • C.

      Allocating CPU to resources

    • D.

      All of the above mentioned

    Correct Answer
    C. Allocating CPU to resources
    Explanation
    The correct answer is "Allocating CPU to resources". A circular linked list is used in the context of allocating CPU to resources because it allows for efficient management of resources in a cyclical manner. This means that once a resource is allocated, it can be deallocated and then reallocated to another process in a continuous loop. This is particularly useful in scenarios where resources need to be shared among multiple processes in a round-robin fashion.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 18, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Mar 04, 2018
    Quiz Created by
    Code_Quest_2k18
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.