Posts

Showing posts from July, 2023

Diamond Problem in C+

Image
Problem:  Diamond problem is the scenario in hybrid or multiple inheritance, when a derived class inherit the 2 or more classes which inherit the same base class. In this case, Derived Class 3 acquires the 2 copies of the Base Class which is inherited by the Derived Class 1 & Derived Class 2. So an ambiguous situation appear while accessing the members of the Base class by Derived Class 3. Diamond Problem in Inheritance Solution : The ambiguity in the above mentioned problem will be removed by making the Base Class virtual by using the virtual keyword while  Derived Class 1 & Derived Class 2 inherit the Base Class. It will pass a single copy to the Derived Class 3, when Derived Class 3 inherit the Derived Class 1 & Derived Class 2. // This code will explain the diamond problem by using Animal Class as Base Class. // Bird - Derived Class 1, Mammal - Derived Class 2, Bat - Derived Class 3 #include < iostream > using namespace std; class Animal { public: ...

Two Number Sum (C++) - Interview Question

Find the two numbers in a given array or vector whose sum is equal to the given target value. Return the index of two numbers, lower index value will be the Index 1 and higher will be Index2 #include < iostream > #include < vector > #include < unordered_map > using namespace std; vector < int > twoSum ( const vector < int > & A , int B ) { unordered_map < int , int > hm ; vector < int > result ; int i ; for ( i = 0 ; i < A . size (); i ++) { int diff = ( B - A [ i ]); if ( hm . find ( diff ) != hm . end ()) { if ( i < hm [ diff ]) { result . push_back ( i + 1 ); result . push_back ( hm [ diff ] + 1 ); } else { result . push_back ( hm [ diff ] + 1 ); result . push_back ( i + 1 ); } return result ; } e...

Static Data Members in C++ Classes

 Static Data Members in C++ Classes Static Data Member : It is a data member of a class that is qualified as static. The properties of a static data member is similar to that of a C static member. Characteristics of a Static Data Member or Static Member Variable : It is initialized to zero when the first object of its class is created. No other initialization is permitted. Only one copy of the that member is created for the entire class and is shared by all the objects of that class, irrespective of the number of objects created. It is visible only within the class, but its lifetime is the entire program.  Static variables are normally used to maintain values common to the entire class.  For example, cur_id is used as a static data member, that increment with the number of object of that class with "putdata()" function.

Vulnerabilities Analysis in Executable

Vulnerabilities Analysis in Executable Static and dynamic analysis are two common techniques used to identify vulnerabilities in executable files. Each approach offers unique benefits and can be used in combination to provide a comprehensive assessment of the security of an executable.