Launch your tech mastery with us—your coding journey starts now!
Course Content
Introduction to C++ Programming
0/2
Control Flow Statements
Control flow statements in C++ allow the program to make decisions, repeat tasks, or jump to specific parts of code based on conditions. These statements give a program logical structure and control over the sequence of execution. Mastering control flow is essential for writing efficient and responsive programs. This section covers decision-making statements, looping constructs, and jump statements in detail with syntax and examples.
0/4
Functions in C++
Functions in C++ are blocks of reusable code designed to perform a specific task. They help break large programs into smaller, manageable pieces and improve readability, modularity, and reusability. Functions reduce code duplication by allowing programmers to call the same block of logic from multiple places. This modular approach also makes debugging easier and enhances program structure and clarity.
0/4
Modern C++ and Concurrency
0/2

C++ Practice & Interview Zone

 

Multiple Choice Questions

 

  1. What is the correct syntax to declare a class in C++?
    a) class myClass { };
    b) Class myClass { }
    c) class myClass;
    d) struct myClass { };
    Answer: a

 

  1. What is the default access specifier for members of a class in C++?
    a) protected
    b) private
    c) public
    d) static
    Answer: b

 

  1. Which of the following is used to dynamically allocate memory in C++?
    a) malloc
    b) alloc
    c) new
    d) calloc
    Answer: c

 

  1. Which operator is used to resolve scope in C++?
    a) ::
    b) .
    c) ->
    d) :
    Answer: a

 

  1. What is the output of this code?

int x = 5;

cout << x++;

  1. a) 6
    b) 5
    c) Error
    d) Undefined
    Answer: b
  2. Which keyword is used to inherit a class in C++?
    a) inherit
    b) extends
    c) public
    d) using
    Answer: c

 

  1. What will this code output?

int x = 10;

int* p = &x;

cout << *p;

  1. a) address of x
    b) garbage
    c) 10
    d) Error
    Answer: c

 

  1. Which constructor is called when an object is created without arguments?
    a) Copy constructor
    b) Default constructor
    c) Parameterized constructor
    d) Virtual constructor
    Answer: b

 

  1. Destructor name is same as constructor but prefixed with:
    a) *
    b) &
    c) ~
    d) #
    Answer: c

 

  1. Which feature allows same function name with different arguments?
    a) Operator Overloading
    b) Function Overriding
    c) Function Overloading
    d) Inheritance
    Answer: c

 

  1. What does STL stand for in C++?
    a) Standard Testing Library
    b) Standard Template Library
    c) System Template Language
    d) Source Template Library
    Answer: b

 

  1. Which of the following is not a container in STL?
    a) vector
    b) list
    c) map
    d) math
    Answer: d

 

  1. What is used to handle exceptions in C++?
    a) if-else
    b) try-catch
    c) switch
    d) error handler
    Answer: b

 

  1. Which of these is a smart pointer in C++11?
    a) auto_ptr
    b) unique_ptr
    c) dynamic_ptr
    d) shared_obj
    Answer: b

 

  1. What is the size of int on most 32-bit systems?
    a) 2 bytes
    b) 4 bytes
    c) 8 bytes
    d) 1 byte
    Answer: b

 

  1. Function templates are used for:
    a) memory management
    b) exception handling
    c) generic programming
    d) runtime polymorphism
    Answer: c

 

  1. Virtual functions are resolved at:
    a) Compile time
    b) Link time
    c) Run time
    d) Preprocessing
    Answer: c

 

  1. Which container does not allow duplicate keys?
    a) multimap
    b) vector
    c) set
    d) multiset
    Answer: c

 

  1. this pointer in C++ refers to:
    a) base class
    b) derived class
    c) current object
    d) none
    Answer: c

 

  1. What is the output of this code?

int a = 4, b = 3;

cout << a % b;

  1. a) 0
    b) 1
    c) 2
    d) Error
    Answer: b

 

  1. Which of the following is a reference operator?
    a) *
    b) &
    c) %
    d) @
    Answer: b

 

  1. Which keyword is used to define constant variables?
    a) static
    b) const
    c) define
    d) final
    Answer: b

 

  1. What is the role of #include in C++?
    a) Compilation
    b) Linking
    c) Header file inclusion
    d) Debugging
    Answer: c

 

  1. What will be the output?

cpp

CopyEdit

string s = “Hello”;

cout << s.length();

  1. a) 4
    b) 5
    c) 6
    d) Error
    Answer: b

 

  1. Which header is required for file handling?
    a) <iostream>
    b) <fstream>
    c) <stdlib.h>
    d) <stdio.h>
    Answer: b

 

  1. Which of the following is used for multithreading?
    a) <thread>
    b) <pthread>
    c) <mutex>
    d) <threads>

Answer: a

 

  1. Which preprocessor directive is used to define macros?
    a) #define
    b) #macro
    c) #include
    d) #typedef
    Answer: a

 

  1. Lambda expressions were introduced in which version of C++?
    a) C++98
    b) C++03
    c) C++11
    d) C++20
    Answer: c

 

  1. Which is not a valid iterator type in STL?
    a) forward_iterator
    b) backward_iterator
    c) random_access_iterator
    d) bidirectional_iterator
    Answer: b

 

  1. Which is used to allocate memory from heap in C++?
    a) new
    b) malloc
    c) calloc
    d) all of the above
    Answer: d

 

  1. typeid is used for:
    a) templates
    b) type casting
    c) type checking at runtime
    d) exception handling
    Answer: c

 

  1. What will the following code return?

cout << sizeof(char);

  1. a) 2
    b) 4
    c) 1
    d) 8
    Answer: c

 

  1. What is the correct syntax of namespace in C++?
    a) namespace name { }
    b) namespace : name { }
    c) namespace => name { }
    d) namespace(name) { }
    Answer: a

 

  1. A class containing at least one pure virtual function is called:
    a) base class
    b) abstract class
    c) virtual class
    d) polymorphic class
    Answer: b

 

  1. How many catch blocks can you have for a try block?
    a) 1
    b) 2
    c) As many as needed
    d) Only one
    Answer: c

 

  1. What is std::pair used for?
    a) Sorting
    b) Memory
    c) Storing two values
    d) File I/O
    Answer: c

 

  1. Which header file is used for vectors?
    a) <vector>
    b) <list>
    c) <map>
    d) <array>
    Answer: a

 

  1. Which C++11 feature allows you to deduce variable type?
    a) const
    b) auto
    c) static
    d) volatile
    Answer: b

 

  1. Which STL container follows FIFO?
    a) stack
    b) queue
    c) vector
    d) map
    Answer: b

 

  1. unique_ptr belongs to which header?
    a) <memory>
    b) <utility>
    c) <thread>
    d) <pointer>
    Answer: a