0% found this document useful (0 votes)
8 views12 pages

CSE202 All VIVA QUESTION

The document contains a comprehensive list of 180 questions and answers covering key concepts in C++ programming, including basics, pointers, file handling, operator overloading, dynamic memory, polymorphism, exception handling, templates, and the Standard Template Library (STL). Each section is organized into units that address specific topics, providing essential definitions, differences, and functionalities relevant to C++. This resource serves as a study guide for understanding fundamental and advanced C++ programming concepts.

Uploaded by

na
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views12 pages

CSE202 All VIVA QUESTION

The document contains a comprehensive list of 180 questions and answers covering key concepts in C++ programming, including basics, pointers, file handling, operator overloading, dynamic memory, polymorphism, exception handling, templates, and the Standard Template Library (STL). Each section is organized into units that address specific topics, providing essential definitions, differences, and functionalities relevant to C++. This resource serves as a study guide for understanding fundamental and advanced C++ programming concepts.

Uploaded by

na
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CSE202 All VIVA QUESTION

UNIT I: Concepts & Basics of C++ Programming + Functions (30 Q&A)

1. What is C++?
C++ is an object-oriented programming language developed by Bjarne
Stroustrup as an extension of C.

2. What are the main features of C++?


OOP, classes, objects, inheritance, polymorphism, encapsulation, abstraction.

3. Difference between C and C++?


C is procedural; C++ supports both procedural and object-oriented
programming.

4. What is a class?
A class is a user-defined data type that groups data members and member
functions.

5. What is an object?
An object is an instance of a class.

6. What is encapsulation?
Binding data and functions together and restricting access using access
specifiers.

7. What are access specifiers?


public, private, protected.

8. What is inline function?


A function expanded at compile time to reduce function call overhead.

9. What is function overloading?


Multiple functions with the same name but different parameters.

10. What is default argument?


A value assigned to a function parameter used when no argument is passed.

11. What is a friend function?


A non-member function that can access private members of a class.

12. Difference between structure and class?


Default access: structure → public, class → private.

13. What is static data member?


A class variable shared among all objects.
14. What is static member function?
A function that accesses only static members.

15. What is scope resolution operator (::)?


Used to access global variables or class members outside the class.

16. What is recursion?


A function calling itself.

17. Call by value?


Copies value; changes do not affect original variable.

18. Call by reference?


Uses reference; changes affect original variable.

19. Call by address?


Uses pointer to pass address.

20. What are manipulators?


Functions like endl, setw() used for formatting output.

21. What is cin and cout?


Objects for input and output streams.

22. What is object-oriented programming?


Programming based on objects instead of functions.

23. What is procedural programming?


Programming based on functions and steps.

24. What is namespace?


Used to avoid name conflicts.

25. What is inline vs macro?


Inline is type-safe; macro is not.

26. What is function prototype?


Declaration of function before definition.

27. What is member function?


Function defined inside a class.

28. What is non-member function?


Function defined outside class.

29. What is header file?


Contains declarations and definitions.
30. Why C++ is better than C?
Supports OOP, security, reusability, abstraction.

UNIT II: Pointers, Reference, Arrays & Strings (30 Q&A)

1. What is a pointer?
A variable that stores address of another variable.

2. What is void pointer?


A pointer without data type.

3. Pointer arithmetic?
Operations like increment, decrement on pointers.

4. What is dangling pointer?


Pointer pointing to freed memory.

5. What is wild pointer?


Uninitialized pointer.

6. What is NULL pointer?


Pointer that points to nothing.

7. Pointer to pointer?
Pointer storing address of another pointer.

8. What is reference variable?


An alias to another variable.

9. Difference between pointer and reference?


Reference cannot be null or reassigned.

10. Array of objects?


Array that stores class objects.

11. Pointer to object?


Pointer pointing to class object.

12. What is this pointer?


Pointer that holds address of current object.

13. What is string class?


Standard C++ class to handle strings.

14. Difference between char array and string?


String is safer and dynamic.
15. Multidimensional array?
Array with more than one dimension.

16. Dynamic array?


Array allocated at runtime.

17. What is memory leak?


Unused allocated memory not freed.

18. Array passing to function?


Passed by reference.

19. What is STL string?


Standard Template Library string class.

20. How to compare strings?


Using == or compare().

21. Pointer to array?


Pointer pointing to first element.

22. *Difference between ptr and &var?


*ptr accesses value; &var gives address.

23. What is constant pointer?


Pointer whose value cannot change.

24. What is pointer constant?


Pointer pointing to constant data.

25. What is segmentation fault?


Illegal memory access.

26. Why references are safer?


No null values.

27. What is array indexing?


Accessing array elements.

28. What is heap memory?


Dynamic memory.

29. What is stack memory?


Static memory.

30. Why string class preferred?


Easy manipulation, safer.
UNIT III: File Handling & Constructors (30 Q&A)

1. What is file handling?


Reading/writing data to files.

2. Types of files?
Text and binary files.

3. File opening modes?


ios::in, ios::out, ios::app, etc.

4. fstream vs ifstream?
fstream → both, ifstream → read only.

5. ofstream?
Used for writing to files.

6. What is binary file?


Stores data in binary format.

7. Random access file?


Access data at any position.

8. seekg()?
Moves read pointer.

9. seekp()?
Moves write pointer.

10. tellg()?
Returns read position.

11. What is constructor?


Special function to initialize object.

12. Default constructor?


Constructor with no arguments.

13. Parameterized constructor?


Constructor with parameters.

14. Copy constructor?


Initializes object using another object.

15. Destructor?
Destroys object and frees memory.

16. When destructor called?


When object goes out of scope.
17. Why destructor needed?
To release resources.

18. Can constructor be virtual?


No.

19. Can destructor be virtual?


Yes.

20. What is initializer list?


Used to initialize data members.

21. Structure file operation?


Writing structure objects to file.

22. EOF?
End of file.

23. File pointer?


Points to file position.

24. Text vs binary file?


Binary is faster.

25. Error handling in file?


Check is_open().

26. What is serialization?


Object stored in file.

27. Can we overload constructor?


Yes.

28. Can destructor take parameters?


No.

29. File closing?


Using close().

30. Advantage of file handling?


Permanent data storage.

UNIT IV: Operator Overloading & Inheritance (30 Q&A)

1. What is operator overloading?


Redefining operators for user-defined types.
2. Which operators cannot be overloaded?
::, ., sizeof, ?:.

3. Unary operator?
Works on single operand.

4. Binary operator?
Works on two operands.

5. Why operator overloading used?


Improves readability.

6. What is type conversion?


Conversion between data types.

7. Class to basic conversion?


Using casting operator.

8. Basic to class conversion?


Using constructor.

9. Inheritance?
Deriving new class from base class.

10. Types of inheritance?


Single, multiple, multilevel, hierarchical, hybrid.

11. Public inheritance?


Public members remain public.

12. Private inheritance?


Public becomes private.

13. Protected inheritance?


Public becomes protected.

14. What is virtual base class?


Prevents diamond problem.

15. Diamond problem?


Ambiguity in multiple inheritance.

16. Function overriding?


Redefining base class function.

17. Virtual function?


Supports runtime polymorphism.
18. Early binding?
Compile-time binding.

19. Late binding?


Runtime binding.

20. Aggregation?
Weak relationship (HAS-A).

21. Composition?
Strong relationship.

22. Base class constructor order?


Called first.

23. Destructor order?


Derived then base.

24. Can we override static function?


No.

25. Ambiguity resolution?


Using scope resolution.

26. Can constructors be inherited?


No.

27. Why virtual destructor?


Proper cleanup.

28. What is abstract class?


Contains pure virtual function.

29. Pure virtual function?


Function with =0.

30. Why inheritance used?


Code reusability.

UNIT V: Dynamic Memory & Polymorphism (30 Q&A)

1. Dynamic memory allocation?


Memory allocated at runtime.

2. new operator?
Allocates memory.
3. delete operator?
Deallocates memory.

4. Difference between malloc and new?


new calls constructor.

5. What is polymorphism?
Many forms of a function.

6. Types of polymorphism?
Compile-time, runtime.

7. Compile-time polymorphism?
Function overloading.

8. Runtime polymorphism?
Function overriding.

9. Virtual function?
Resolved at runtime.

10. Virtual table?


Table for virtual functions.

11. Abstract class?


Cannot be instantiated.

12. Concrete class?


Can be instantiated.

13. Self-referential class?


Contains pointer to same class.

14. Pure virtual function?


No definition.

15. Memory leak?


Unused memory not freed.

16. Dangling pointer?


Points to deallocated memory.

17. What is heap?


Dynamic memory area.

18. What is stack?


Static memory.
19. Why virtual destructor?
To avoid memory leak.

20. What is RTTI?


Runtime Type Identification.

21. What is dynamic_cast?


Used in polymorphism.

22. Why base class pointer?


Achieve polymorphism.

23. Object slicing?


Loss of derived part.

24. Can static function be virtual?


No.

25. Can constructor be virtual?


No.

26. Memory allocation failure?


Returns NULL or exception.

27. delete[] vs delete?


Array vs single object.

28. What is shallow copy?


Copies pointer address.

29. Deep copy?


Copies actual data.

30. Why polymorphism needed?


Flexibility and scalability.

UNIT VI: Exception Handling, Templates & STL (30 Q&A)

1. What is exception?
Runtime error.

2. try block?
Code that may throw exception.

3. catch block?
Handles exception.
4. throw keyword?
Throws exception.

5. Multiple catch?
Handling different exceptions.

6. Rethrowing exception?
Throw again from catch.

7. Why exception handling?


Prevent program crash.

8. What is template?
Generic programming.

9. Function template?
Generic function.

10. Class template?


Generic class.

11. Template specialization?


Specific implementation.

12. STL?
Standard Template Library.

13. STL components?


Containers, algorithms, iterators.

14. Vector?
Dynamic array.

15. List?
Doubly linked list.

16. Iterator?
Points to container element.

17. Advantages of STL?


Reusable, efficient.

18. Algorithm example?


sort(), find().

19. Container types?


Sequence, associative.
20. Map container?
Key-value pair.

21. Set container?


Unique values.

22. Queue?
FIFO.

23. Stack?
LIFO.

24. Deque?
Double-ended queue.

25. Exception vs error?


Exception handled, error not.

26. Can templates be overloaded?


Yes.

27. Compile-time polymorphism?


Templates.

28. STL header?


<vector>, <algorithm>.

29. Iterator types?


Input, output, forward, bidirectional, random.

30. Why STL preferred?


Efficiency and speed.

You might also like