In this tutorial, we will be discussing a program to understand Type interference in C++ (auto and decltype). In the case of auto keyword, the type of the variable is defined from the type of its initializer. Further, with decltype, it lets you extract the type of variable from the called element. auto type Example Here is the following example of auto-type in C++. #include using namespace std; int main() { auto x = 4; auto y = 3.37; auto ptr = & x; cout
In this problem, we are given an array bin[] of size n of binary strings. Our task is to create a program to find the Bitwise AND (&) of N binary strings. Here, we will take all numbers and find the bitwise AND of them i.e. bin[0] & bin[1] &... bin[n-2] & bin[n] Example Let’s take an example to understand the problem. Input − bin[] = {“1001”, “11001”, “010101”} Output − 000001 Explanation Bitwise AND of all binary strings − (1001) & (11001) & (010101) = 000001 To solve this problem, ... Read More
In this tutorial, we are going to write a program that finds the largest difference between the two elements in the given array. Approach Let's look at the approach we will follow to solve this problem. Firstly, we will initialize the array. Then we will find or search for the max and min elements in the array. And will return max - min. Example Here is the following code for finding the largest gap in an array in C++. #include using namespace std; ... Read More
Armstrong Number Armstrong number is a number in which the sum of its digits raised to the power of the number of digits is equal to the number itself. In this article, we are going to discuss how we can check if a given number is Armstrong number or not. Examples Let's understand Armstrong's Number with the help of some input-output examples. Input 9474 Output Yes Explanation This is a four digit-number. The digit in this number are 9, 4, 7 and 4. 9474 = 94 + 44 + 74 + 44= 6561 + 256 + 2401 + 256= ... Read More
To check whether a given number is power of 2 in JavaScript, we can check if the number is generated using multiplying 2's only. We will be discussing 5 different approaches to check whether a given number is a power of 2. In this article we are having two numbers, our task is to check whether a given number is power of 2 in JavaScript. Users must be familiar with JavaScript Math functions, loops, binary representation and bitwise operators. Approaches to Check if a Number is Power of 2 Here is a list of approaches to check whether ... Read More
strdup() The function strdup() is used to duplicate a string. It returns a pointer to a null-terminated byte string. Syntax Here is the syntax of strdup() in C language, char *strdup(const char *string); Example Here is an example of strdup() in C language. #include #include int main() { char *str = "Helloworld"; char *result; result = strdup(str); printf("The string : %s", result); return 0; } Output The string : Helloworld strndup() The function strndup works similarly to the function strndup(). This function duplicates the string at most size bytes i.e. the given size in the function. It also returns ... Read More
In C++ the structure and class are basically the same. But there are some minor differences. These differences are like below. The class members are private by default, but members of structures are public. Let us see these two codes to see the differences. Example Code for Class Here is the following code for the class. #include using namespace std; class my_class { public: int x = 10; }; int main() { my_class my_ob; cout
Complex numbers are numbers that are expressed as a+bi, where i is an imaginary number and a and b, are real numbers. Some examples of complex numbers are − 2+3i 5+9i 4+2i Example A program to perform complex number multiplication is as follows − #include using namespace std; int main(){ int x1, y1, x2, y2, x3, y3; cout y1; cout y2; x3 = x1 * x2 - y1 * y2; y3 = x1 * y2 + y1 * x2; cout
In this tutorial, we are going to learn how to delete a node in the doubly linked list. Approach Let's see the steps to solve the problem. Write struct with data, prev, and next pointers. Write a function to insert the node into the doubly linked list. Initialize the doubly ... Read More
This is a simple way to read whole ASCII file into std::string in C++ − Algorithm Here is the algorithm we will follow to Read the whole ASCII file into C++ std::string. Begin Declare a file a.txt using file object f of ifstream type to perform a read operation. Declare a variable str of string type. If(f) Declare another variable ss of ostringstream type. Call rdbuf() function to read the data of the file object. Put the ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP