Concepts in C++
1. Difference between Map and Unordered_Map :
2. setprecision() :
Setprecision when used along with ‘fixed’ provides precision to floating point numbers correct to decimal numbers mentioned in the brackets of the setprecison.
3. Value of INT_MAX and INT_MIN:
4. Difference Between BFS and DFS
S.NO | BFS | DFS |
1. | BFS stands for Breadth First Search. | DFS stands for Depth First Search. |
2. | BFS(Breadth First Search) uses Queue data structure for finding the shortest path. | DFS (Depth First Search) uses Stack data structure. |
3. | The Time complexity of BFS is O(V + E) when Adjacency List is used and O(V^2) when Adjacency Matrix is used, where V stands for vertices and E stands for edges. | The Time complexity of DFS is also O(V + E) when Adjacency List is used and O(V^2) when Adjacency Matrix is used, where V stands for vertices and E stands for edges. |
5. Difference between c and c++
C | C++ |
C does not support object oriented programming. | C++ supports polymorphism, encapsulation, and inheritance because it is an object oriented programming language. |
C does not support information hiding. | Data is hidden by the Encapsulation to ensure that data structures and operators are used as intended. |
6. Can we access global variable if there is a local variable with same name?
we cannot access a global variable if we have a local variable with same name, but it is possible in C++ using scope resolution operator (::)
7. Static Keyword and Use of Static
Static keyword has different meanings when used with different types. We can use static keyword with:
Static Variables : Variables in a function, Variables in a class Static Members of Class : Class objects and Functions in a class
Static variables in a Function:
When a variable is declared as static, space for it gets allocated for the lifetime of the program. Even if the function is called multiple times, space for the static variable is allocated only once and the value of variable in the previous call gets carried through the next function call.
Static variables in a class:
As the variables declared as static are initialized only once as they are allocated space in separate static storage so, the static variables in a class are shared by the objects. There can not be multiple copies of same static variables for different objects.
This gives an error as we cannot create multiple copies for different object
Class objects as static:
Just like variables, objects also when declared as static have a scope till the lifetime of program. Consider the below program where the object is non-static.
Output:
In the above program the object is declared inside the if block as non-static. So, the scope of variable is inside the if block only. So when the object is created the constructor is invoked and soon as the control of if block gets over the destructor is invoked as the scope of object is inside the if block only where it is declared. Let us now see the change in output if we declare the object as static.
Output:
You can clearly see the change in output. Now the destructor is invoked after the end of main. This happened because the scope of static object is through out the life time of program.
Static functions in a class:
Just like the static data members or static variables inside the class, static member functions also does not depend on object of class. We are allowed to invoke a static member function using the object and the ‘.’ operator but it is recommended to invoke the static members using the class name and the scope resolution operator. Static member functions are allowed to access only the static data members or other static member functions, they can not access the non-static data members or member functions of the class.
Output:
Main use of static keyword is memory management
8. Authentication vs. Authorization
What Is Authentication?
Authentication is the act of validating that users are whom they claim to be. This is the first step in any security process. Complete an authentication process through:
Passwords. Usernames and passwords are the most common authentication factors. If a user enters the correct data, the system assumes the identity is valid and grants access.
One-time pins. Grant access for only one session or transaction.
Authentication apps. Generate security codes via an outside party that grants access.
Biometrics. A user presents a fingerprint or eye scan to gain access to the system.
In some instances, systems require the successful verification of more than one factor before granting access. This multi-factor authentication (MFA) requirement is often deployed to increase security beyond what passwords alone can provide.
What Is Authorization?
Authorization in a system security is the process of giving the user permission to access a specific resource or function. This term is often used interchangeably with access control or client privilege.
In secure environments, authorization must always follow authentication. Users should first prove that their identities are genuine before an organization’s administrators grant them access to the requested resources
9. What are namespaces and use of using namespace std
Namespaces allow us to group named entities. Namespaces are spaces which help us to resolve conflicts between same variable names.
std stands for standard namespace which contains declaration of various objects like cout, endl, string etc.
10. Sorting algorithms time complexity
Algorithm | Time Complexity | ||
Best | Average | Worst | |
Ω(n^2) | θ(n^2) | O(n^2) | |
Ω(n) | θ(n^2) | O(n^2) | |
Ω(n) | θ(n^2) | O(n^2) | |
Ω(n log(n)) | θ(n log(n)) | O(n log(n)) | |
Ω(n log(n)) | θ(n log(n)) | O(n^2) | |
Ω(n log(n)) | θ(n log(n)) | O(n log(n)) | |
Ω(n+k) | θ(n+k) | O(n^2) |
Last updated