C/C++ Language

  1. What is the output of the following C code?
    C
    int x = 5;
    printf(“%d %d %d”, x, x++, ++x);
    A) 5 5 7
    B) Undefined behavior ✅
    C) 5 6 7
    D) 7 6 5
  2. In C++, which keyword is used to prevent inheritance?
    A) final ✅
    B) static
    C) const
    D) sealed
  3. What does sizeof(‘A’) return in C?
    A) 1
    B) 2
    C) 4 ✅
    D) Depends on compiler
  4. Which feature is not part of OOP?
    A) Encapsulation
    B) Polymorphism
    C) Compilation ✅
    D) Inheritance
  5. Which storage class has the longest lifetime?
    A) auto
    B) register
    C) static
    D) extern ✅
  6. What is the default access specifier in a class in C++?
    A) public
    B) private ✅
    C) protected
    D) friend
  7. Which operator is used for pointer dereferencing?
    A) &
    B) * ✅
    C) ->
    D) .
  8. What is the result of 10 % 3?
    A) 1 ✅
    B) 3
    C) 0
    D) 10
  9. Which function is used to allocate memory in C?
    A) new
    B) malloc() ✅
    C) alloc()
    D) create()
  10. Which is not a valid C++ data type?
    A) int
    B) float
    C) real ✅
    D) char
  11. What is function overloading?
    A) Same function name with different parameters ✅
    B) Same function name same parameters
    C) Different functions same return type
    D) Recursive functions
  12. Which symbol is used for preprocessor directive?
    A) $
    B) # ✅
    C) @
    D) &
  13. What is the size of pointer in 64-bit system?
    A) 2 bytes
    B) 4 bytes
    C) 8 bytes ✅
    D) 16 bytes
  14. Which loop executes at least once?
    A) for
    B) while
    C) do-while ✅
    D) none
  15. Which keyword is used to define constant in C?
    A) final
    B) const ✅
    C) define
    D) static
  16. What is recursion?
    A) Looping
    B) Calling function within itself ✅
    C) Memory allocation
    D) Pointer usage
  17. What is virtual function?
    A) Static function
    B) Inline function
    C) Runtime polymorphism function ✅
    D) Private function
  18. Which operator is used to access structure member?
    A) ->
    B) . ✅
    C) *
    D) &
  19. Which header file is required for printf()?
    A) stdlib.h
    B) conio.h
    C) stdio.h ✅
    D) math.h
  20. Which keyword is used to dynamically allocate memory in C++?
    A) malloc
    B) new ✅
    C) alloc
    D) dynamic
  21. What is inheritance?
    A) Code reuse mechanism ✅
    B) Function call
    C) Looping
    D) Compilation
  22. Which is correct pointer declaration?
    A) int p
    B) int *p ✅
    C) *int p
    D) int &p
  23. Which concept binds data and functions together?
    A) Inheritance
    B) Polymorphism
    C) Encapsulation ✅
    D) Abstraction
  24. What is operator overloading?
    A) Redefining operators ✅
    B) Looping operators
    C) Pointer usage
    D) Compilation
  25. Which function frees allocated memory?
    A) free() ✅
    B) delete
    C) remove()
    D) release()
  26. What is namespace in C++?
    A) Variable
    B) Class
    C) Scope resolution tool ✅
    D) Function
  27. Which keyword is used to inherit class?
    A) inherits
    B) extends
    C) : ✅
    D) super
  28. What is the output of sizeof(int) in most systems?
    A) 2
    B) 4 ✅
    C) 8
    D) 16
  29. Which is not a loop structure?
    A) for
    B) while
    C) repeat-until ✅
    D) do-while
  30. Which operator is used for address-of variable?
    A) *
    B) & ✅
    C) ->
    D) .
  31. What is polymorphism?
    A) Many forms of function ✅
    B) Single function
    C) Looping
    D) Pointer
  32. Which function is entry point in C program?
    A) start()
    B) main() ✅
    C) init()
    D) run()
  33. Which keyword is used to define class?
    A) struct
    B) class ✅
    C) object
    D) define
  34. Which is used to handle exception?
    A) catch
    B) throw
    C) try
    D) All of these ✅
  35. What is abstraction?
    A) Hiding implementation details ✅
    B) Loop
    C) Memory
    D) Pointer
  36. Which operator is used for member access via pointer?
    A) .
    B) -> ✅
    C) *
    D) &
  37. Which data type stores single character?
    A) int
    B) char ✅
    C) float
    D) double
  38. Which keyword is used for inline function?
    A) inline ✅
    B) static
    C) virtual
    D) extern
  39. What is dangling pointer?
    A) Valid pointer
    B) Null pointer
    C) Pointer to freed memory ✅
    D) Pointer to array
  40. Which concept supports code reusability?
    A) Inheritance ✅
    B) Loop
    C) Pointer
    D) Function
  41. What is default return type of main()?
    A) void
    B) int ✅
    C) char
    D) float
  42. Which operator has highest precedence?
    A) *
    B) +
    C) () ✅
    D) =
  43. What is function prototype?
    A) Function body
    B) Declaration of function ✅
    C) Loop
    D) Pointer
  44. Which storage class restricts scope to file?
    A) static ✅
    B) extern
    C) auto
    D) register
  45. Which is not a valid keyword in C++?
    A) virtual
    B) friend
    C) export
    D) include ✅
  46. What is friend function?
    A) Member function
    B) External function with access to private data ✅
    C) Inline function
    D) Virtual function
  47. Which concept allows same function name different behavior?
    A) Overloading ✅
    B) Encapsulation
    C) Loop
    D) Pointer
  48. Which keyword is used to exit loop?
    A) continue
    B) break ✅
    C) stop
    D) exit
  49. Which operator is used for scope resolution?
    A) :
    B) :: ✅
    C) .
    D) ->
  50. Which concept allows hiding data?
    A) Encapsulation ✅
    B) Polymorphism
    C) Inheritance
    D) Loop

Leave a Comment