C++ Imp
C++ Imp
&
Explain characteristics of OOP?
x = 10
if x > 5:
print("x is greater than 5")
'else' statement: If the condition in the 'if' statement is false, the
code within the 'else' block gets executed. For instance:
x=3
if x > 5:
print("x is greater than 5")
else:
print("x is less than or equal to 5")
6) Explain Concept of Pointer variables?
Ans:- Pointer variables in programming languages like C, C++, and
others are variables that store memory addresses as their values.
Instead of directly storing data, they store the location (address) of
where data is stored in memory. They allow you to indirectly access
and manipulate data by referring to its memory address. This can be
particularly powerful for tasks like dynamic memory allocation,
passing functions as arguments, and working with complex data
structures. However, if not used carefully, they can also lead to bugs
like segmentation faults or memory leaks.
7) What is Array of Pointer?
Ans:- Pointer variables in programming languages like C, C++, and
others are variables that store memory addresses as their values.
Instead of directly storing data, they store the location (address) of
where data is stored in memory. They allow you to indirectly access
and manipulate data by referring to its memory address. This can be
particularly powerful for tasks like dynamic memory allocation,
passing functions as arguments, and working with complex data
structures. However, if not used carefully, they can also lead to bugs
like segmentation faults or memory leaks.
8) Explain Recursive Function in details?
Ans:- A recursive function is a function that calls itself within its
definition. This technique allows a function to solve a problem by
breaking it down into smaller instances of the same problem. A
recursive function typically has two parts: a base case that specifies
when the recursion should stop, and a recursive case that defines
how the function calls itself with modified arguments to move
towards the base case.
int main() {
int x = 5, y = 10;
}
11) Different Between class and object?
Ans:- Class:- In object-oriented programming, a class is a blueprint or
template for creating objects. It defines the properties (attributes)
and behaviors (methods) that objects of that class will have. Think of
a class as a general description or a set of instructions for creating
objects with specific characteristics and behaviors.
};
class B {
public:
void modifyPrivateVar(A &obj, int val) {
obj.privateVar = val; // Accessing privateVar in class
A } };
int main() {
return 0;
}
14) What is Inheritance? Explain their types
Ans:- Inheritance in programming refers to the mechanism by which
a new class can inherit properties, methods, and behaviors from an
existing class. This helps in creating a hierarchy and facilitates
reusability.
Ex:- class A {
public:
int dataA; };
public:
int dataB; };
public:
int dataC; };
public:
int dataD; };
int main() {
D obj;
}
16) Explain Operator Overloading with example?
Ans:- Operator overloading allows operators like +, -, *, /, etc., to be
used with user-defined types. For instance, you can define how the '+'
operator works for your custom class objects.
Call by reference:
Function call by reference meante while calling a of actual Function
the sailue argument is copled inte Formal argument and any changes
in Formal argument also changes andaal arguement because both are
seferes to same memory Location.