Found 7197 Articles for C++

fmax() and fmin() in C++

Akansha Kumari
Updated on 02-Jun-2025 15:18:31

587 Views

The fmax() and fmin() functions in C++ are used to check the maximum or minimum of two floating-point numbers. These functions are defined under the header file of the C++ standard library. C++ fmax() function The fmax() is used to compare and return the larger of two floating-point values. These floating point values can be float, double, and long double. Syntax data_type fmax(data_type value_1, data_type value_2); Here, data_type could be float, double and long double. C++ fmin() function The fmin() is used to compare and return the smaller of two floating-point values. These floating point values can be float, ... Read More

Constructor Delegation in C++

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

1K+ Views

Here we will see what is the constructor delegation? When a constructor calls other constructor of the same class, then it is called the constructor delegation. This feature is present from C++11.Let us see the following program, and try to analyze what are the difficulties in this code.Example#include using namespace std; class MyClass {    int a, b, c;    public:    MyClass(){       a = b = c = 0;    }    MyClass(int c) {       // Initializing a and b are redundent, only c initialization is needed here       a = 0;       b = 0;       this->c = c;    }    void display(){       cout

C++ set for user define data type

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

907 Views

Here we will see how we can make a set for user defined datatypes. The Set is present in C++ STL. This is a special type of data structure, it can store data in sorted order, and does not support duplicate entry. We can use set for any type of data, but here we will see how we can also use set for userdefined datatypes.To use user-defined datatypes into stack, we have to override < operator, that can compare two values of that type. If this is not present, it cannot compare two objects, so the set cannot store data ... Read More

Data Type Ranges and their macros in C++

Akansha Kumari
Updated on 29-May-2025 18:56:08

2K+ Views

In some cases, especially in competitive programming, we may need to specify the minimum or maximum value of a specific datatype. In C++, each data type has a different memory range under which we can define and declare the value of that data type. But it becomes difficult to remember all the large ranges of each data type. So, C++ has introduced the macros that are used to represent the minimum and maximum range of some datatype. And some data types do not have macros for minimum values, because they are unsigned (means, hold only positive value). So, as their ... Read More

Signal Handling in C++

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

583 Views

Signals are the interrupts delivered to a process by the operating system which can terminate a program prematurely. You can generate interrupts by pressing Ctrl+C on a UNIX, LINUX, Mac OS X or Windows system.There are signals which cannot be caught by the program but there is a following list of signals which you can catch in your program and can take appropriate actions based on the signal. These signals are defined in C++ header fileSignalDescriptionSIGABRTAbnormal termination of the program, such as a call to abort.SIGFPEAn erroneous arithmetic operation, such as a divide by zero or an operation resulting in ... Read More

Difftime() C library function

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

174 Views

Here we will see what is the difftime() function in C. The difftime() is used to get the differences between two time values.difftime() takes two time argument, the first one is the lower bound, and the second one is the upper bound. And it returns the differences between these two arguments.Example#include #include #include main() {    int sec;    time_t time1, time2;    time(&time1);    printf("Current Time: %ld",time1);    for (sec = 1; sec

Foreach in C++ vs Java

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

213 Views

In C++ and Java, there is another kind of loop, called the foreach loop. This is basically a modification of for loop. This loop is used to access the data from some container. This can access the elements of some array quickly without performing initialization. This loop is used to do something for each element of a container, not doing things n times.Now let us see how the foreach loop is used in C++ and Java.Example#include using namespace std; int main() {    int arr[] = { 11, 22, 33, 44, 55, 66, 77, 88, 99 };    for (int a : arr) //foreach loop    cout

Difference between Structures in C and C++

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

520 Views

Here we will see what are the differences between structures in C and structures in C++. The C++ structures are mostly like classes in C++. In C structure, all members are public, but in C++, they are private in default. Some other differences are listed below.C StructureC++ StructureStructures in C, cannot have member functions inside structures.Structures in C++ can hold member functions with member variables.We cannot initialize the structure data directly in C.We can directly initialize structure data in C++.In C, we have to write ‘struct’ keyword to declare structure type variables.In C++, we do not need to use ‘struct’ ... Read More

Type difference of character literals in C vs C++

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

188 Views

In C++ the size of the character constants is char. In C the type of character constant is integer (int). So in C the sizeof(‘a’) is 4 for 32bit architecture, and CHAR_BIT is 8. But the sizeof(char) is one byte for both C and C++.Example#include main() {    printf("%d", sizeof('a')); }Output4Example#include using namespace std; main(){    cout

Compile 32-bit program on 64-bit gcc in C and C++

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

1K+ Views

Nowadays the compiler comes with default 64-bit version. Sometimes we need to compile and execute a code into some 32bit system. In that time, we have to use thisS feature.At first, we Shave to check the current target version of the gcc compiler. To check this, we have to type this command.gcc –v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu ........... ........... ...........Here it is showing that Target is x86_64. So we are using the 64-bit version of gcc. Now to use the 32-bit system, we have to write the following command.gcc –m32 program_name.cSometimes this command may generate ... Read More

Advertisements