C/C++ Language

  1. What is the output of the following C++ code?
    C++
    int x = 10;
    cout << (x++ + ++x);
    A) 21
    B) 22
    C) Undefined behavior ✅
    D) 20
  2. Which of the following correctly defines a reference variable in C++?
    A) int *ref = a;
    B) int &ref = a; ✅
    C) ref int = a;
    D) int ref = &a;
  3. Which function is used to compare two strings in C?
    A) strcompare()
    B) strcmp() ✅
    C) compare()
    D) strcomp()
  4. Which keyword is used to prevent a function from being overridden?
    A) static
    B) const
    C) final ✅
    D) virtual
  5. What does NULL represent?
    A) 1
    B) 0 or no address ✅
    C) -1
    D) Garbage value
  6. Which of the following is a correct destructor declaration?
    A) className() ✅
    B) destructor()
    C) className()
    D) delete()
  7. Which operator is overloaded by default in C++?
    A) +
    B) = ✅
    C) *
    D) /
  8. What is multiple inheritance?
    A) One class inherits from one class
    B) One class inherits from multiple classes ✅
    C) Multiple classes inherit from one class
    D) None
  9. Which keyword is used to declare constant pointer?
    A) const int *p
    B) int *const p ✅
    C) constant pointer
    D) static pointer
  10. Which function is used to release memory in C++?
    A) free()
    B) release()
    C) delete ✅
    D) remove()
  11. What is the purpose of this pointer?
    A) Points to class
    B) Points to current object ✅
    C) Points to function
    D) Points to memory
  12. Which header file is used for string functions?
    A) stdlib.h
    B) string.h ✅
    C) stdio.h
    D) math.h
  13. Which keyword is used to define macro?
    A) macro
    B) define
    C) #define ✅
    D) #macro
  14. What is the output of:
    C
    printf(“%d”, 5/2);
    A) 2 ✅
    B) 2.5
    C) 3
    D) Error
  15. Which of the following is not a type of inheritance?
    A) Single
    B) Multiple
    C) Hybrid
    D) Parallel ✅
  16. What is a pure virtual function?
    A) Virtual function without body ✅
    B) Inline function
    C) Static function
    D) Private function
  17. Which keyword is used for exception throwing?
    A) catch
    B) try
    C) throw ✅
    D) error
  18. Which symbol is used for logical AND?
    A) &
    B) && ✅
    C) ||
    D) !
  19. What is function template?
    A) Generic function ✅
    B) Recursive function
    C) Inline function
    D) Virtual function
  20. Which loop is best when number of iterations is known?
    A) while
    B) do-while
    C) for ✅
    D) none
  21. What is memory leak?
    A) Memory overflow
    B) Unreleased allocated memory ✅
    C) Null pointer
    D) Buffer overflow
  22. Which operator is used for bitwise AND?
    A) &&
    B) & ✅
    C) ||
    D) ^
  23. What is the output of:
    C
    int a=5;
    printf(“%d”, a<<1);
    A) 5
    B) 10 ✅
    C) 2
    D) 20
  24. Which keyword is used for inheritance access control?
    A) public ✅
    B) class
    C) friend
    D) new
  25. What is call by reference?
    A) Passing value
    B) Passing address/reference ✅
    C) Passing pointer
    D) Passing function
  26. Which operator is used for ternary condition?
    A) :
    B) ? : ✅
    C) ::
    D) ->
  27. What is stack memory used for?
    A) Dynamic allocation
    B) Static allocation
    C) Function calls and local variables ✅
    D) Global variables
  28. Which keyword is used for default function arguments?
    A) default ✅
    B) auto
    C) const
    D) static
  29. What is the output of:
    C
    printf(“%d”, sizeof(float));
    A) 2
    B) 4 ✅
    C) 8
    D) 16
  30. Which function is used to open file in C?
    A) open()
    B) fopen() ✅
    C) fileopen()
    D) create()
  31. Which operator is used for bitwise OR?
    A) ||
    B) | ✅
    C) &
    D) ^
  32. What is inline function?
    A) Function inside class
    B) Function expanded at compile time ✅
    C) Runtime function
    D) Recursive function
  33. Which keyword is used to define structure in C?
    A) class
    B) struct ✅
    C) union
    D) typedef
  34. Which of the following is correct file closing function?
    A) close()
    B) fclose() ✅
    C) fileclose()
    D) endfile()
  35. What is operator precedence?
    A) Operator priority ✅
    B) Loop
    C) Function
    D) Pointer
  36. Which keyword is used for pointer to constant?
    A) const int *p ✅
    B) int *const p
    C) constant pointer
    D) pointer const
  37. What is buffer overflow?
    A) Memory leak
    B) Exceeding buffer limit ✅
    C) Pointer error
    D) Syntax error
  38. Which keyword is used for virtual inheritance?
    A) virtual ✅
    B) static
    C) final
    D) friend
  39. Which function reads character from file?
    A) getchar()
    B) fgetc() ✅
    C) getcfile()
    D) read()
  40. What is segmentation fault?
    A) Compilation error
    B) Runtime memory access violation ✅
    C) Syntax error
    D) Linker error
  41. Which operator is used for bitwise XOR?
    A) ^ ✅
    B) &
    C) |
    D) ~
  42. What is class template?
    A) Generic class ✅
    B) Static class
    C) Virtual class
    D) Abstract class
  43. Which keyword is used to create object?
    A) new
    B) class
    C) object
    D) None (objects are declared normally) ✅
  44. Which is not a valid loop control statement?
    A) break
    B) continue
    C) exit
    D) return ✅
  45. What is the output of:
    C
    printf(“%d”, 3*2+4);
    A) 10 ✅
    B) 14
    C) 12
    D) 8
  46. Which keyword is used for file scope variable?
    A) extern ✅
    B) static
    C) auto
    D) register
  47. What is copy constructor?
    A) Constructor with no arguments
    B) Constructor with same class reference ✅
    C) Destructor
    D) Default constructor
  48. Which operator is used to allocate memory in array dynamically in C++?
    A) malloc
    B) new[] ✅
    C) alloc
    D) array()
  49. Which is not a feature of C++?
    A) OOP
    B) Platform dependent
    C) Garbage collection ✅
    D) Strong typing
  50. What is abstraction in C++?
    A) Showing only essential features ✅
    B) Looping
    C) Memory allocation
    D) Pointer

Leave a Comment