C++ Articles - Page 620 of 719

What's the difference between __PRETTY_FUNCTION__, __FUNCTION__, __func__ in C/C++?

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

2K+ Views

Here we will see what are the differences between __FUNCTION__, __func__ and the __PRETTY_FUNCTION__ in C++.Basically the __FUNCTION__ and __func__ are same. Some old versions of C and C++ supports __func__. This macro is used to get the name of the current function. The _PRETTY_FUNCTION__ is used to return the detail about the function. Using this we can get which function is used, and in which class it is belonging, etc.Example#include using namespace std; class MyClass{    public:       void Class_Function(){          cout

What is a reentrant function in C/C++?

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

4K+ Views

Here we will see what is the reentrant function in C or C++. One function is said to be a reentrant function if there is a provision to interrupt that function in the course of execution, then service the ISR (Interrupt Service Routine) and then resume the task. This type of functions is used in different cases like, recursions, hardware interrupt handling.For a reentrant function there should be some properties. These are listed below −This type of function will not use any global or static variable. There are no restrictions, but it is generally not advised. This is because the ... Read More

What is converting constructor in C++ ?

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

211 Views

In this section we will see what is the conversion constructor or converting constructor in C++ class. A constructor is a special type of function of class. It has some unique property like, its name will be same as class name, it will not return any value etc. The constructors are used to construct objects of a class. Sometimes constructors may take some arguments, or sometimes it does not take arguments.When a constructor takes only one argument then this type of constructors becomes conversion constructor. This type of constructor allows automatic conversion to the class being constructed.Example#include using namespace std; ... Read More

What is an unsigned char in C++?

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

6K+ Views

In C++ we have seen there is character type data called char. Sometimes we have seen unsigned char also. So here we will see what is basically the unsigned char means. What are the basic differences between signed char and unsigned char?Signed char and unsigned char both are used to store single character. The variable stores the ASCII value of the characters. For an example if ‘A’ is stored, actually it will hold 65. For signed char we need not to write the signed keyword. But for unsigned, we have to mention the keyword. The syntax is like below.unsigned char ... Read More

Meaning of 'const' last in a function declaration of a C++ class?

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

826 Views

Sometimes we can find the keyword ‘const’ present at the last of function declaration. So what does it mean?Using this one function can be made as constant. The idea of constant function is that, the function cannot be modified from the objects, where they are called. It is recommended to use the constant functions in our program.Let us see one example of constant function.Example#include using namespace std; class MyClass {    int value;    public:       MyClass(int val = 0) {          value = val;       }       int getVal() const ... Read More

How to initialize private static members in C++?

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

24K+ Views

Here we will see how to initialize the private static member variables initialization in C++. We can put static members (Functions or Variables) in C++ classes. For the static variables, we have to initialize them after defining the class.To initialize we have to use the class name then scope resolution operator (::), then the variable name. Now we can assign some value.The following code will illustrate the of static member initializing technique.Example#include using namespace std; class MyClass{    private:       static int st_var;    public:       MyClass(){          st_var++; //increase the value ... Read More

C++ Program to Perform Baillie-PSW Primality Test

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

628 Views

The Baillie-PSW Primality Test, this test named after Robert Baillie, Carl Pomerance, John Selfridge, and Samuel Wagstaff. It is a test which tests whether a number is a composite number or possibly prime.AlgorithmMillerTest()Begin    Declare a function MillerTest of Boolean type.    Declare MT_dt and MT_num of integer datatype and pass as the parameter.    Declare MT_a and MT_x of integer datatype.       Initialize MT_a = 2 + rand( ) % (MT_num - 4).       Initialize MT_x = pow(MT_a, MT_dt, MT_num).    if (MT_x == 1 || MT_x == MT_num - 1) then       ... Read More

C++ Program to Implement the Solovay-Strassen Primality Test to Check if a Given Number is Prime

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

335 Views

Solovay-Strassen Primality Test is used to test a number whether it is a composite or possibly prime number.AlgorithmsBegin    Declare a function modulo to the long datatype to perform binary calculation.       Declare m_base, m_exp, m_mod of long datatype and pass them as a parameter.       Declare two variables a, b of long datatype.          Initialize a = 1, b = m_base.       while (m_exp > 0) do          if (m_exp % 2 == 1) then             a = (a * b) % ... Read More

C++ Program to Find the Vertex Connectivity of a Graph

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

736 Views

To find the Vertex Connectivity of a graph we need to find out Articulation Points of that graph. Articulation Points (or Cut Vertices) in a Graph is a point iff removing it (and edges through it) disconnects the graph. An articulation point for a disconnected undirected graph, is a vertex removing which increases number of connected components.AlgorithmBegin    We use dfs here to find articulation point:    In DFS, a vertex w is articulation point if one of the following two conditions is satisfied.    1) w is root of DFS tree and it has at least two children.   ... Read More

C++ Program to Find the Maximum Cut in a Graph

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

611 Views

In this program to find the maximum Cut in a graph, we need to find the Edge Connectivity of a Graph. An Edge Connectivity of a Graph of a graph means it is a bridge, removing it graph will be disconnected. Number of connected components increases with the removing of bridge in a disconnected undirected graph.Functions and pseudocodeBegin    Function connections() is a recursive function to find out the connections:    A) Mark the current node un visited.    B) Initialize time and low value    C) Go through all vertices adjacent to this    D) Check if the subtree ... Read More

Advertisements