[go: up one dir, main page]

0% found this document useful (0 votes)
13 views6 pages

CPP

c++ interview / viva

Uploaded by

abhishes39561
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)
13 views6 pages

CPP

c++ interview / viva

Uploaded by

abhishes39561
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
You are on page 1/ 6

1. What is C++?

C++ is a general-purpose programming language that supports both procedural and object-oriented programming
paradigms.

2. What are Class and Object?

A class is a blueprint for creating objects; an object is an instance of a class containing data and functions.

3. Difference between C and C++?

C is procedural; C++ supports both procedural and object-oriented programming, offering features like classes and
objects.

4. Explain Operators in C++.

Operators perform operations on variables and values, such as arithmetic (+, -, *, /), relational (==, !=), and logical
(&&, ||).

5. What are Virtual Functions?

Virtual functions allow derived classes to override functions in base classes, enabling dynamic polymorphism.

6. What is Inheritance?

Inheritance allows a class (derived) to acquire properties and behaviors from another class (base).

7. What is Polymorphism?

Polymorphism allows functions or methods to behave differently based on the object that invokes them.

8. What is Encapsulation?

Encapsulation is the bundling of data and methods that operate on that data within a single unit, like a class.

9. What is Abstraction?

Abstraction hides complex implementation details and shows only the necessary features of an object.

10. Difference between Overloading and Overriding?

Overloading allows multiple functions with the same name but different parameters; overriding allows a derived
class to provide a specific implementation of a function already defined in its base class.

11. What are Constructors and Destructors?

Constructors initialize objects; destructors clean up resources when objects are destroyed.
12. What is the 'this' Pointer?

'this' is a pointer that refers to the current object instance.

13. What is Operator Overloading?

Operator overloading allows customizing the behavior of operators for user-defined types.

14. What is the Difference between 'new' and 'malloc'?

'new' initializes objects and calls constructors; 'malloc' allocates memory without initialization.

15. What is a Friend Function?

A friend function can access private and protected members of a class, even though it is not a member of the class.

16. What is the STL?

The Standard Template Library (STL) provides a set of common classes and interfaces for data structures and

algorithms.

17. What are Templates?

Templates allow functions and classes to operate with generic types, enabling code reuse.

18. What is Exception Handling?

Exception handling manages errors through 'try', 'catch', and 'throw' blocks to maintain normal program flow.

19. What is a Namespace?

Namespaces prevent naming conflicts by encapsulating identifiers.

20. What is the Difference between Struct and Class?

In C++, structs have public members by default; classes have private members by default.

21. What is a Virtual Destructor?

A virtual destructor ensures that the destructor of the derived class is called when deleting an object through a base
class pointer.

22. What is Function Overloading?

Function overloading allows multiple functions with the same name but different parameters.
23. What is the Difference between Shallow Copy and Deep Copy?

A shallow copy copies object references; a deep copy copies the actual objects.GeeksforGeeks+4BTree+4PREP
INSTA+4

24. What is the Use of 'static' Keyword?

The 'static' keyword can define class-level variables, functions, or restrict variable scope within a file.

25. What is the Difference between '==' and 'equals()' in C++?

In C++, '==' compares values; 'equals()' is not standard in C++ (more common in Java).

26. What is RTTI?

Run-Time Type Information (RTTI) allows the type of an object to be determined during program execution.

27. What is the Difference between 'delete' and 'delete[]'?

'delete' deallocates memory for a single object; 'delete[]' deallocates memory for an array of objects.

28. What is a Pure Virtual Function?

A pure virtual function is a function declared in a base class that must be overridden in derived classes.

29. What is the Difference between 'public', 'private', and 'protected' Access Specifiers?

'public' members are accessible from anywhere; 'private' members are accessible only within the class; 'protected'
members are accessible within the class and its derived classes.

30. What is the Use of 'mutable' Keyword?

The 'mutable' keyword allows a member of an object to be modified even if the object is declared as const.

31. What is the Difference between Stack and Heap Memory?

Stack memory is used for static memory allocation; heap memory is used for dynamic memory allocation.

32. What is the Use of 'const' Keyword?

The 'const' keyword declares variables as constant, meaning their value cannot be changed after initialization.

33. What is the Difference between 'const' and '#define'?

'const' defines a constant variable with a specific type; '#define' creates a macro without type checking.
34. What is the Use of 'volatile' Keyword?

The 'volatile' keyword tells the compiler that a variable's value may change at any time, preventing certain
optimizations.

35. What is the Difference between 'struct' and 'union'?

In a 'struct', each member has its own memory; in a 'union', all members share the same memory location.PREP
INSTA

36. What is the Use of 'typedef'?

'typedef' creates a new name (alias) for an existing type.

37. What is the Difference between 'throw', 'try', and 'catch'?

'try' defines a block of code to test for errors; 'catch' defines a block of code to handle errors; 'throw' is used to
signal the occurrence of an exception.

38. What is the Use of 'explicit' Keyword?

The 'explicit' keyword prevents the compiler from using implicit conversions for constructors.

39. What is the Difference between 'overloading' and 'overriding'?

Overloading allows multiple functions with the same name but different parameters; overriding allows a derived
class to provide a specific implementation of a function already defined in its base class.

40. What is a Copy Constructor?

A copy constructor creates a new object as a copy of an existing object.

41. What is the Use of 'inline' Function?

An 'inline' function suggests to the compiler to insert the function's code at the point of call to reduce function call
overhead.

42. What is the Difference between 'call by value' and 'call by reference'?

'Call by value' passes a copy of the variable; 'call by reference' passes the variable itself, allowing modifications.

43. What is the Use of 'enum'?

An 'enum' defines a set of named integral constants, improving code readability.

44. What is the Difference between 'break' and 'continue'?

'break' exits the current loop; 'continue' skips the current iteration and proceeds to the next.
45. What is the Use of 'goto' Statement?

The 'goto' statement transfers control to a labeled statement; its use is generally discouraged due to readability
concerns.

46. What is the Difference between '++i' and 'i++'?

'++i' increments the value before use; 'i++' increments the value after use.

47. What is the Use of 'sizeof' Operator?

The 'sizeof' operator returns the size, in bytes, of a data type or object.

48. What is the Difference between 'union' and 'structure'?

In a 'union', all members share the same memory location; in a 'structure', each member has its own memory

location.

49. What is the Use of 'auto' Keyword?

The 'auto' keyword allows the compiler to automatically deduce the type of a variable from its initializer.

50. What is the Difference between 'public', 'private', and 'protected' Inheritance?

In 'public' inheritance, public and protected members of the base class remain public and protected in the derived
class; in 'private' inheritance, they become private; in 'protected' inheritance, they become protected.

51. What is a lambda function in C++?

Lambda functions are anonymous functions used for short operations, often passed to algorithms like std::sort.

52. What is the Rule of Three (or Five) in C++?

If you define a custom destructor, copy constructor, or copy assignment operator, you should usually define all three.
In modern C++, the rule of five includes move constructor and move assignment operator.

53. What is the difference between deep copy and move semantics?

Deep copy duplicates objects and their contents; move semantics transfers resources from one object to another,
avoiding copies.

54. What are smart pointers in C++?

Smart pointers (unique_ptr, shared_ptr, weak_ptr) automatically manage memory and prevent leaks.
55. What is std::move and when is it used?

std::move casts an object to an rvalue to enable move semantics (e.g., for performance).

56. What is the use of std::vector in C++?

std::vector is a dynamic array provided by the STL, offering efficient insertions and deletions at the end.

57. What are the containers in STL?

Containers include vector, list, deque, map, set, unordered_map, etc., used to store and manipulate data.

58. What is RAII (Resource Acquisition Is Initialization)?

RAII ensures resource allocation and deallocation are tied to object lifetime using constructors/destructors.

59. What is the difference between map and unordered_map?

map is ordered and uses a red-black tree; unordered_map is faster but unordered and uses hash tables.

60. What is the difference between std::list and std::vector?

vector is a dynamic array; list is a doubly linked list. Use list for frequent insertions/deletions.

You might also like