Nishtha Thakur has Published 568 Articles

Checking if a double (or float) is NaN in C++

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:25

12K+ Views

To check whether a floating point or double number is NaN (Not a Number) in C++, we can use the isnan() function. The isnan() function is present into the cmath library. This function is introduced in C++ version 11. So From C++11 next, we can use this function.Example#include #include ... Read More

Differences between pass by value and pass by reference in C++

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:25

16K+ Views

In C++ we can pass arguments into a function in different ways. These different ways are −Call by ValueCall by ReferenceCall by AddressSometimes the call by address is referred to as call by reference, but they are different in C++. In call by address, we use pointer variables to send ... Read More

Why is a C++ pure virtual function initialized by 0?

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:25

2K+ Views

It’s just a syntax, nothing more than that for saying that “the function is pure virtual”.A pure virtual function is a virtual function in C++ for which we need not to write any function definition and only we have to declare it. It is declared by assigning 0 in declaration.Here ... Read More

How are virtual functions implemented in C++?

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:25

578 Views

Virtual functions in C++ used to create a list of base class pointers and call methods of any of the derived classes without even knowing kind of derived class object. Virtual functions are resolved late, at runtime.Here is an implementation of virtual function in C++ program −Example#include using namespace ... Read More

Default virtual behavior in C++ vs Java

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:25

119 Views

In C++ methods are non-virtual by default. They can be made virtual function by using a virtual keyword.Example Code#include using namespace std; class B {    public: void s() //non virtual by default. Use virtual before the function to print “In Derived” {       cout

How do I INSERT INTO from one MySQL table into another table and set the value of one column?

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:25

265 Views

Let us first create a table. Following is the query −mysql> create table insertOneToAnotherTable    -> (    -> Value int    -> ); Query OK, 0 rows affected (0.60 sec)Following is the query to insert some records in the table using insert command −mysql> insert into insertOneToAnotherTable values(100); Query ... Read More

C++ Program to Implement Coppersmith Freivald’s Algorithm

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:25

373 Views

Freivalds' algorithm determines whether the matrices are equal for a chosen k value with a probability of failure less than 2^-k in O(kn^2).It is used to verify matrix multiplication.AlgorithmBegin    Take matrix1(n*n), matrix2(n*n), matrix3(n*n) as input.    // According to the algorithm we have to verify:    // matrix1 × ... Read More

Template Metaprogramming in C++

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:25

214 Views

When we write programs to do computation at compile time using a template, that is called Template Metaprogramming.Example Code#include using namespace std; templatestruct power {    enum { value = 4*power::value }; }; templatestruct power {    enum { value = 1 }; }; int main() {    cout

Why use static_cast(x) instead of (int)x in C++?

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:25

2K+ Views

The (int)x is C style typecasting where static_cast(x) is used in C++. This static_cast() gives compile time checking facility, but the C style casting does not support that. This static_cast() can be spotted anywhere inside a C++ code. And using this C++ cast the intensions are conveyed much better.In C ... Read More

C++ Program to implement Slicker Algorithm that avoids Triangulation to find Area of a Polygon

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:25

81 Views

Here is a C++ program to find the area of polygon using slicker algorithm that avoids Triangulation to find area of a polygon.It assumes the usual mathematical convention that positive y points upwards. In computer systems where positive y is downward, the easiest thing to do is to list the ... Read More

Advertisements