Interview Quetions and Answers ?
The latest official C++ standard is C++23.
It was developed by Bjarne Stroustrup in 1985.
#include <iostream> → used for input/output
using namespace std → allows using standard functions for remove space
main() → starting point of program
cout → prints output
cin → Take input from user
endl → Line Break
return 0 → program ends successfully
cout is pronounced "see-out". Used for output, and uses the insertion operator (<<)
cin is pronounced "see-in". Used for input, and uses the extraction operator (>>)
C++ most popular Object Orineted Programming Language (OOPs)
C++ was developed as an extension of C
Supports classes and objects
C++ is used for system software and games
Main features are:
Object-Oriented Programming
Classes and Objects
Inheritance
Polymorphism
Encapsulation
Data Abstraction
A constructor is a special function that is automatically called when an object is created.
Same name as class
Constructor doesn't have any return type
Only called onece (automatically), Object creaction
A destructor is a special function that is automatically called when an object is destroyed.
It is mainly used to free memory or clean up resources.
Example: Closing files, releasing memory, deleting pointers.
Destructor name is the same as the class name
It has a tilde (~) before the name
#include <iostream>
using namespace std;
class Test {
public:
Test() {
cout << "Constructor called" << endl;
}
~Test() {
cout << "Destructor called" << endl;
}
};
int main() {
Test obj;
}It has no return type
It takes no parameters
It is called automatically
A pointer is a variable that stores the memory address of another variable. Instead of storing a value, it stores where the value is located in memory.
int *ptr; //This means ptr is a pointer that can store the address of an integer variable.Dynamic memory allocation
Passing arguments to functions
Working with arrays
Efficient memory use
#include <iostream>
using namespace std;
int main() {
int a = 10;
int *ptr;
ptr = &a;
cout << "Value of a: " << a << endl;
cout << "Address of a: " << &a << endl;
cout << "Pointer value (address): " << ptr << endl;
cout << "Value using pointer: " << *ptr << endl;
return 0;
}int a = 10;Create variable a
int *ptr;Create pointer to integer
ptr = &a;Store address of a in ptr
&aAddress of variable a
*ptrValue stored at that address
&Address-of operator
*Pointer / Dereference operator
C is a procedural language focused on functions.
C++ is an object-oriented language focused on classes and objects.

Access specifiers in C++ are used to control the accessibility (visibility) of class members such as variables and functions.
They help in data hiding and security of a program.
There are three main types of access specifiers:
Public - Members declared as public can be accessed from anywhere in the program.
#include <iostream>
using namespace std;
class Student {
public:
int age;
void show() {
cout << age;
}
};
int main() {
Student s;
s.age = 20;
s.show();
}Accessible inside the class
Accessible outside the class
Accessible by derived (child) classes
Mostly used for functions that interact with objects
Protected - Members declared as protected can be accessed inside the class and by derived (child) classes, but not outside the class.
class Parent {
protected:
int value;
};
class Child : public Parent {
public:
void setValue() {
value = 10;
}
};Accessible inside the class
Accessible in derived classes (inheritance)
Not accessible outside the class
Mainly used in inheritance
Private - Members declared as private can be accessed only inside the class.
class Demo {
private:
int num;
public:
void setNum() {
num = 5;
}
};Accessible inside the class only
Not accessible outside the class
Not accessible in derived classes
Used for data hiding

0
1
0