In C, the strings are basically array of characters. In C++ the std::string is an advancement of that array. There are some additional features with the traditional character array. The null terminated strings are basically a sequence of characters, and the last element is one null character (denoted by '\0'). When we write some string using double quotes ("..."), then it is converted into null terminated strings by the compiler. The size of the string may smaller than the array size, but if there are some null character inside that array, that will be treated as the end of that ... Read More
In C++, function overloading and const keyword are used for different purposes. Function overloading provides different ways to call a function with different parameter types that make the program more readable. While the const keyword provides the ways of declaration such as variable, member variable, function parameters, member function, and return type. What is Function Overloading? Function overloading is the process of defining multiple functions having the same name but different parameter lists. It is also known as compile-time polymorphism. Here, we have list of three points to describe function overloading in C++: The parameter ... Read More
In C++, you can read data from a text file using file handling features provided by the header. This is useful when you want your program to read input stored in a file instead of typing it every time. To do this, you use a special object called ifstream (input file stream), which helps your program open the file and read its contents line by line or word by word. Reading a text file is helpful when: You want to process saved data (like scores, settings, or logs). You want to ... Read More
Listing files in a directory is used to write a program that opens a specified folder (e.g: "/myfiles"), reads its contents, and displays the names of each file and subfolder one by one. In C/C++, to see all the files in a directory, you can use special system functions that let you read the directory's contents. In real life, we open folder to see the contents inside the files. Similarly, in C or C++, we can write a program to display all the files and folders in a directory. Algorithm Following is the algorithm to get the list of files ... Read More
The auto and decltype serve different purposes so they don't map one-to-one. The auto is a keyword in C++11 and later that is used for automatic type deduction. The decltype type specifier yields the type of a specified expression. Unlike auto that deduces types based on values being assigned to the variable, decltype deduces the type from an expression passed to it. The value returned by decltype can directly be used to define another variable. The auto follows the rules of template parameter deduction. You can read more about these rule at Template Argument Deduction While decltype has rules it ... Read More
Type inference (or type deduction) refers that the compiler can figure out the datatype of a variable or expression automatically, without the programmer needing to write it out. This feature is available in many strongly typed languages like C++, where the type system is strict but the compiler helps to reduce the typing effort. Following is the simple example to understand the type deduction in C++. #include using namespace std; int main() { // Let the compiler deduce the type from the value auto number = 50; // int auto pi = 3.14; // double cout
In C++, the keywords signed and unsigned are used to specify that a given variable can hold negative values or only positive values. In this article, we will learn the differences between these two in more detail. C++ signed Keyword The signed keyword specifies that the given variable can hold both positive and negative values. Most integers, like int, short, long, etc, are by default signed (meaning they can store both positive and negative values). When an integer is represented in binary form, the most significant bit (MSB) or the leftmost bit represents the sign of the integer. When the most significant ... Read More
In this article, we will learn how to insert all elements from one list into another in Java. This is a general operation we perform when working with lists while solving problems in Java. We will cover the following methods to insert all elements from one list into another: Using addAll() Method Using For Loop Using Stream API Using ListIterator Using addAll() Method We can add all elements of one list into another list easily using its addAll() method. This method appends all of the elements in the specified collection to the end of this list, in the ... Read More
Yes, we can insert null values into a list easily using its add() method. In case of List implementation does not support null, then it will thrown a NullPointerException List is an interface in Java that extends the Collection interface and provides a way to store an ordered collection of elements. It allows us to store duplicate elements, and it also maintains the order of insertion. The List interface is implemented by classes such as ArrayList, LinkedList, and Vector. Null Values in a Java List In Java, a List can contain null values. The List interface allows for the insertion of ... Read More
An octahedron is a three-dimensional (3D) shape which has eight plane faces. In other words, a polyhedron is called an octahedron which has eight faces, twelve edges, and 6 vertices. A polygonal is a three-dimensional figure with flat polygonal faces, straight edges, and sharp corners or vertices. The word octahedron is derived from the Greek word that is Oktaedron, which means Eight faces. Here is the diagram of the octahedron, which has side a: Volume of octahedron The volume of an octahedron is the amount of space occupied by the octahedron. To calculate the volume of an octahedron, we ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP