Found 7347 Articles for C++

Virtual Copy Constructor in C++

sudhir sharma
Updated on 16-Oct-2019 06:32:23

4K+ Views

Before digging deep into the topics lets brush up all the related terms.A copy constructor is a special type of constructor that is used to create an object that is an exact copy of the object that is passed.A virtual function is a member function that is declared in the parent class and is redefined ( overridden) in a child class that inherits the parent class.With the use of a virtual copy constructor, the programmer will be able to create an object without knowing the exact data type of the object.In C++ programming language, copy Constructor is used to creating ... Read More

What is OpenMP?

Arnab Chakraborty
Updated on 11-Oct-2019 12:45:48

7K+ Views

OpenMP is a set of compiler directives as well as an API for programs written in C, C++, or FORTRAN that provides support for parallel programming in shared-memory environments. OpenMP identifies parallel regions as blocks of code that may run in parallel. Application developers insert compiler directives into their code at parallel regions, and these directives instruct the OpenMP run-time library to execute the region in parallel. The following C program illustrates a compiler directive above the parallel region containing the printf() statement −#include #include int main(int argc, char *argv[]){    /* sequential code */    #pragma omp ... Read More

C/C++ Pointer Puzzle?

sudhir sharma
Updated on 07-Oct-2019 08:19:16

286 Views

A Pointer is a variable that stores the address of another variable. The data type of the pointer is the same as the data type as the variable.In this puzzle you need to know the size of the pointer that is being used. The puzzle checks our understanding of pointers by asking you the size of variable.The size of int is 4 bytes, whereas the size of int pointer is 8. Now, let’s test your skills with the following exercise in c++ programming language.Example Live Demo#include using namespace std; int main() {    int a = 6 ;    int ... Read More

C/C++ Function Call Puzzle?

sudhir sharma
Updated on 07-Oct-2019 08:14:43

143 Views

This C/C++ function call puzzle is a puzzle that is intended to explore more about the behaviour of method calling in both the programming languages C and C++/.The output of a method in C and C++ is different. Lets see what is the difference in calling methods in C and C++.Let’s take an example and check the output of the below code in c and c++.Example Live Demovoid method() {    // Print statement } int main() {    method();    method(2); }OutputFor C++ −Error : too many arguments to function ‘void method()’For C −Program runs without any error.Logic behind the ... Read More

C++ Boolean Matrix

sudhir sharma
Updated on 07-Oct-2019 08:12:21

730 Views

Boolean matrix is a matrix that has only two elements 0 and 1. For this boolean Matrix question, we have a boolean matrix arr[m][n] of size mXn. And the condition to solve is, if m[i][j] = 1 then m[i] = 1 and m[j] = 1 which means all elements of the ith row and jth column will become 1.Let’s take an example, Input: arr[2][2] = 1 0                   0 0 Output: arr[2][2] = 1 1                   1 0Explanation− arr[0][0] = 1 ... Read More

C++ Adam Number

sudhir sharma
Updated on 07-Oct-2019 08:06:37

2K+ Views

Adam Number is a number whose square is reverse of the square of its reverse.Concept Explained − For a number to be adam number, the square of number is reverse of the square of the reverse of the number. Let’s take an example, 12 is the number. Square of 12 is 144 and the reverse of 12 is 21. The square of reverse of 12 i.e. 21 is 441. 441 is the reverse of 144 which is the square of 12.Algorithm to check if a number is adam number −Given the number xy, find the square of the number (xy)2.For ... Read More

C++ program to Adding elements of an array until every element becomes greater than or equal to k

sudhir sharma
Updated on 07-Oct-2019 07:36:17

116 Views

We have array of unsorted element i.e. arr[] and have an integer K, and we have to find the minimum number of steps needed in which the elements of the array will be added to make all the elements greater than or equal to K. We can add two elements of array and make them one.Example, Input: arr[] = {1 10 12 9 2 3}, K = 6 Output: 2ExplanationFirst we can add (1 + 2), so the new array is 3 10 12 9 3, we can add (3 + 3), So the new array is 6 10 12 ... Read More

C++ program for the Array Index with same count of even or odd numbers on both sides?

sudhir sharma
Updated on 04-Oct-2019 08:27:33

241 Views

Finding the array index with the same count of even or odd number is a number that has equal number of either numbers or odd number on both sides of it i.e. no.s at left = no.s right.Here, we need a few definitions that are related to the concept, Array − A container of elements of same data type.Array Index − The position of an element is called its index. Index of array always start from 0.Even number − A number that is divisible by 2.Odd number − A number that is not divisible by 2.A whole number can either ... Read More

Array elements with prime frequencies in C++?

sudhir sharma
Updated on 04-Oct-2019 08:22:18

182 Views

Array is a container of elements of same data type.Prime Frequencies means that the number of occurrence of the element of the array is a prime number.So, based on these definitions the problem to find array elements with prime frequencies. We are given a string of array. We have to find the frequency of characters and check if frequency is prime and then count elements that have prime frequencies.Let’s take an example, Input: str = “helloworld” Output: 2ExplanationCount of occurrences of characters are −h -> 1 e -> 1 l -> 3 o -> 2 w-> 1 r -> 1 ... Read More

Array element with minimum sum of absolute differences in C++?

sudhir sharma
Updated on 04-Oct-2019 08:08:14

293 Views

This program is to find minimum absolute difference of the array given we have an array which have distinct element.To learn this concept better let’s rebrush the things that required, Array is a container of elements of same data type. The length of an array needs to be predefined.absolute difference is the absolute value of the difference between two numbers i.e. the difference will always be positive, negative values will be converted to positive.The sum of minimum absolute difference of each element has to be found the minimum absolute solute difference formula isMinimum Absolute Difference (a) = min(abs(a – arr[j])) ;where 1 ... Read More

Advertisements