The variables, which are declared inside a function, block or method are known as local variables in C++. Their scope is limited to that function or block and can be accessed and used only within the area or scope they are defined. You cannot access or use them outside their scope. This is mainly used to prevent conflicts with other variables in other parts of the program and to efficiently manage memory. Key Characteristics of Local Variables Scope Limited : These variables are declared inside block or scope (usually {}) and are only visible and used ... Read More
C++ is a high level programming language that is used to develop applications, work with operating systems, and much more. It is an extension of the C language, which combines both procedural programming (available in C) and object oriented programming. In this article, we will learn step by step the procedure of writing our first C++ program. Prerequist For this, make sure that your computer consists of the following two. C++ Compiler Text Editor or IDE Get a C++ Compiler It is a system that translates the source code (written ... Read More
C++, also said to be a middle-level language, as it is a combination of both high-level features like abstraction with low-level language features like memory manipulation capabilities of assembly. It is a superset of C, as it compromises both C with object-oriented, therefore any valid C program will also be valid to C++ program.Top Features of C++ Programming Language C++ runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX. In this following article we will discuss some of the features of C++ that make it stand out among other programming languages: 1. ... Read More
The rule of three in C++ states that, if a class in C++ has any one (or more) of the following, then it should define all three. Destructor Copy Constructor Copy Assignment Constructor These three are special member functions of class and are responsible for managing resources such as dynamic memory, file handles, sockets, etc. And if one of them is defined explicitly, means that class is managing those resources manually (like memory using new/delete), and if we fail to define others then it can lead to ... Read More
In this section we will see when we declare a variable that is un-initialized, then which value they hold in C or C++ language.What Happens When You Don’t Initialize Variables? In C and C++, when a variable is declared inside a function (i.e., as a local variable) but not explicitly initialized, it holds an undefined or garbage value. This means the variable may contain any value that is present at that memory location.Unlike some high-level languages where variables are automatically initialized (e.g., 0 for integers, false for booleans), C and C++ do not initialize local variables by default. So, assuming ... Read More
C++ Volatile KeywordIn C++, the volatile keyword is a type qualifier that tells the compiler that the value of a variable may be changed at any time unexpectedly, so it should not optimize access to that variable. This change in a variable may be influenced by any external factors such as hardware, signal handlers, or concurrent threads. This concept of volatile is mostly used when working with systems programming, embedded systems, and multi-threaded applications. SyntaxHere, a variable is declared volatile, which means the compiler volatile data_type variable_name; Example This example represents a variable whose value may be changed from an external source. ... Read More
In Python, a list is a built-in data structure that is used to store an ordered collection of multiple items in a single variable. Lists are mutable that means we can add, remove, and change its elements. In this article, we will learn how we can add the corresponding elements of two Python Lists. You are given two equal sized lists in Python and your task is to create a new list containing sum of corresponding elements of the lists.Consider the following input output scenario:Scenario Input: List1 = [3, 6, 9, 45, 6] List2 = [11, 14, 21, ... Read More
The Depth First Search (DFS) algorithm can be used to check whether a graph is bipartite by coloring the graph using two colors. This section will discuss how DFS traversal can be used to check if a graph is bipartite. First of all, let's understand what a bipartite graph is. What is Bipartite Graph? A bipartite graph is a special type of graph where you can divide the vertices into two sets, such that no two vertices of the same set are connected. This is why it's possible to color a bipartite graph using just two colors. Technically, a ... Read More
In Python, tuples are used to store immutable sequence of elements. A nested tuple is a tuple that contains one or more tuples as their elements. For example: # A tuple in Python tup = ( 1, 2, 3, 4 ) # A nested tuple in Python nestedTup = ( (1, 2), (3, 4) ) You are given two nested tuples in Python, and your task is to add corresponding elements of those tuples.Consider the following example scenario:Scenario Input tuples: tup1 = ((7, 8), (3, 4), (3, 2)) tup2 = ((9, 6), (8, 2), (1, 4)) ... Read More
In Python, tuples are used to store an immutable sequence of elements. In this article, we will learn different methods to implement a Python program to add corresponding elements of tuples. Here, you are given two equally sized tuples in Python and your task is to create a new tuple containing sum of corresponding elements of the tuples. Consider the following example scenario:Scenario Input Tuples: tup1 = (3, 6, 9, 45, 6) tup2 = (11, 14, 21, 0, 6) Output: (14, 20, 30, 45, 12 ) Explanation: The corresponding elements that are added to get ... Read More