Posts

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.

Firmware (Software for Hardware)

  Embedded Firmware Design Document Firmware  is often referred to as “software for hardware”. Firmware provides instructions to help hardware start up, communicate with other devices, and perform basic input/output tasks.  There are typically three levels of firmware: Low-level firmware: This firmware is usually stored in non-volatile memory chips like read-only memory (ROM) and one-time programmable (OTP) memory. These chips cannot be rewritten or updated, and the firmware is intrinsic to the hardware, such as a computer. High-level firmware: This firmware is deployed within flash memory chips and comes with more complex instructions that allow updates to be made. Subsystems: These are semi-independent devices that are part of a more extensive system. Firmware at this level is embedded within central processing units (CPUs), flash chips, and liquid crystal display (LCD) units. Types of firmware :  BIOS (Basic Input/Output System) :- The Basic Input/O...

GIT COMMANDS

  Commands to start a Project in Git Repository  :- 𝗴𝗶𝘁 𝗶𝗻𝗶𝘁 : This is the very first command you'll need to use when starting a new project. It initializes a new Git repository in your current directory. 𝗴𝗶𝘁 𝗰𝗹𝗼𝗻𝗲 <𝗿𝗲𝗽𝗼> : To work on an existing project, you'll want to clone (copy) it to your local machine. This command does that. Commands to 𝗠𝗮𝗸𝗲 𝗖𝗵𝗮𝗻𝗴𝗲𝘀 :- 𝗴𝗶𝘁 𝘀𝘁𝗮𝘁𝘂𝘀 : Before making or after making changes, it's good practice to check the status of your files. This command will show you any changes that are currently upstaged. 𝗴𝗶𝘁 𝗮𝗱𝗱 <𝗳𝗶𝗹𝗲𝗻𝗮𝗺𝗲> : After you've made some changes to your files, you'll want to stage them for a commit. This command adds a specific file to the stage. 𝗴𝗶𝘁 𝗮𝗱𝗱 . 𝗼𝗿 𝗴𝗶𝘁 𝗮𝗱𝗱 -𝗔 : Instead of adding files one by one, you can add all your changed files to the stage with one command. 𝗴𝗶𝘁 𝗰𝗼𝗺𝗺𝗶𝘁 -𝗺 "𝗖𝗼𝗺𝗺𝗶𝘁 𝗺𝗲𝘀𝘀𝗮𝗴𝗲" : Now that your ...

Create a autorun for a PyQt5 raspberry pi Application

Create a autorun for a PyQt5 raspberry pi Application :  To create an autorun for a PyQt5 Python application on a Raspberry Pi, you can follow these steps: Create a script that will run your PyQt5 application. Let's call it "DemoApp.py". Make sure that the script is executable by running the command chmod +x App_Script.sh . Open the rc.local file by running the command sudo nano /etc/rc.local . Add the following line to the file, just before the "exit 0" line: ' sudo python3 /path/to/ App_Script.sh  &'. S ave the file and exit. The next time your Raspberry Pi boots up, the script " App_Script.sh " will automatically run and your PyQt5 application will start. Note: If your PyQt5 application requires any specific environment variables or other dependencies to run properly, you may need to modify the script or add additional commands to the rc.local file to ensure that these requirements are met before running the application.