Found 7346 Articles for C++

Is there any need of “long” data type in C and C++?

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

95 Views

In C or C++, there are four different datatypes, that are used for integer type data. These four datatypes are short, int, long and long long. Each of these datatypes takes different memory spaces. The size varies in different architecture and different operating systems. Sometimes int takes 4-bytes or sometimes it takes 2-bytes. This also happen for the compilers. So we can use cross compilers.The cross compilers are basically a compiler, which is capable of compiling for a platform other than current platform.So if we want to compile the following code in 32bit system, and 64-bit system, it will generate ... Read More

Using return value of cin to take unknown number of inputs in C++

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

1K+ Views

Sometimes we need variable number of inputs in our program. In this program we will see how to use cin to take variable number of inputs.The simple solution is run a loop, and when one specific value is pressed, it stops. The another idea is using the cin >> input. This will return false when value is non-numeric.Example#include using namespace std; main() {    int input;    int n = 0;    cout > input)    n++;    cout

lrint() and llrint() in C++

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

67 Views

In this section we will see the lrint() and llring() in C++. At first let us discuss about the lrint().The lrint() function is used to round the fractional given value in the argument to an integral value using current rounding mode. The current mode is determined by using fesetround().>=This lrint() function takes the double or float or integer value as input parameter, and returns the long int value by rounding the fractional part into an integral part.Example#include #include #include using namespace std; main() {    int x = 40;    long int res;    fesetround(FE_DOWNWARD); // setting ... Read More

fdim() in C++

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

97 Views

Here we will see what is the fdim() function in C++. The fdim() function is used to return the positive difference between two given arguments. If two arguments are a and b respectively, and if a >b, then it will return a – b. otherwise returns 0.Example#include #include using namespace std; main() {    cout

fmax() and fmin() in C++

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

448 Views

In this section we will see how to convert fmax() and fmin() in C++. The fmax() and fmin() are present in the cmath header file.This function takes two values of type float, or double or long double and returns maximum or minimum using fmax() and fmin() respectively.If the argument types are different, like if someone wants to compare float and double, or long double with float, then the function typecasts into that value implicitly, then returns the corresponding value.Example#include #include #include using namespace std; main() {    double res;    //uses of fmax()    res = fmax(50.0, ... 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

663 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++

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

2K+ Views

In some cases, we need to use the minimum or maximum value of a specific datatype in different problems. It is very difficult to remember that value. For that reason, C++ has some macros, that are used to denote the minimum and maximum range of some datatype. Some of them do not have macros, because they are unsigned, so the minimum will be 0.Data TypeRangeMacro for min valueMacro for max valuechar-128 to +127CHAR_MINCHAR_MAXshort char-128 to +127SCHAR_MINSCHAR_MAXunsigned char0 to 255-----UCHAR_MAXshort int-32768 to +32767SHRT_MINSHRT_MAXunsigned short int0 to 65535-----USHRT_MAXint-2147483648 to +2147483647INT_MININT_MAXunsigned int0 to 4294967295-----INT_MAXlong int-2147483648 to +2147483647LONG_MINLONG_MAXunsigned long int0 to 18446744073709551615-----ULONG_MAXlong long int-9223372036854775808 ... Read More

Signal Handling in C++

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

419 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

112 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

Advertisements