C++ Articles

Page 284 of 597

How to throw a C++ exception?

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 302 Views

Exception handling is used to handle the exceptions. We can use try catch block to protect the code. Exception can be thrown anywhere within the code block. The keyword “throw” is used to throw an exception.Here is an example of throw in C++ language,Example#include using namespace std; int display(int x, int y) {    if( y == 0 ) {       throw "Division by zero condition!";    }    return (x/y); } int main () {    int a = 50;    int b = 0;    int c = 0;    try {       c = display(a, b);       cout

Read More

frexp() in C++

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 164 Views

The function frexp() is used to break the floating point number into its binary significand and integral exponent for 2. It returns the binary significand and its range is (0.5, 1). If we pass value zero, its significand and exponent value will be zero.Here is the mathematical expression of frexp(), x = significand * (2^exponent)Here is the syntax of frexp() in C++ language, float frexp(float variable_name, int* exponent);Here, variable_name  − Any name of variable which has floating number to be decomposed into binary significant.exponent  − It is a pointer to int where value of exponent is stored.Here is an example ...

Read More

log1p() in C++

Arjun Thakur
Arjun Thakur
Updated on 11-Mar-2026 151 Views

The function log1p() is used to calculate the natural logarithm (base e logarithm) of (a+1) where a is any number. It returns the value of natural logarithm of (a+1). It returns Not a number(Nan) when we pass a value which is less than -1.Here is the mathematical expression of log1p(), log1p(a) = base-e log(a+1)Here is the syntax of log1p() in C++ language, float log1p(float variable_name);Here, variable_name  − Any name given to the variable whose logarithmic value is calculated.Here is an example of log1p() in C++ language, Example#include #include using namespace std; int main() {    int x ...

Read More

expm1() in C++

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 94 Views

The function expm1() is used to calculate the exponential raised to the power of any number minus one. It returns the value of (exponential raised to the power of a) - 1.Here is the mathematical expression of expm1(),expm1(a) = (e^a) - 1Here is the syntax of expm1() in C++ language,float expm1(variable_name);Here,variable_name − Any name given to the variable whose value is calculated.Here is an example of expm1() in C++ language,Example#include #include using namespace std; int main() {    int x = 10;    float y = 8.28;    cout

Read More

remquo() in C++

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 108 Views

The function remquo() is used to calculate the floating point remainder of numerator or denominator and stores the quotient to the passed pointer. It returns Nan(Not a number) when denominator is zero.Here is the syntax of remquo() in C++ language, float remquo(float var1, float var2, int* var3);Here, var1  − The variable which stores the value of numerator.var2  − The variable which stores the value of denominator.var3  − The pointer variable which stores the quotient.Here is an example of remquo() in C++ language, Example#include #include using namespace std; int main() {    float x = 28.8;   ...

Read More

isgreater() in C/C++

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 376 Views

The function isgreater() is used to check that the first argument is greater than the second one or not. It is declared in “math.h” header file in C language. It returns true, if successful, otherwise false.Here is the syntax of isgreater().bool isgreater(value1 , value2);Here, value1 − This is the first argument which will be checked with value2.value2 − This is the second argument which is used to check value1 that is greater or not.Here is an example of isgreater().Example#include #include using namespace std; int main() {    int val1 = 28;    int val2 = 8;    bool result;   ...

Read More

atexit() function in C/C++

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 452 Views

The function atexit() is used to call the function after the normal exit of program. The program is called without any parameters. The function atexit() is called after exit(). The termination function can be called anywhere in the program. This function is declared in “stdlib.h” header file.Here is the syntax of atexit() in C language, int atexit(void (*function_name)(void))Here, function_name − The function is to be called at the time of termination of program.Here is an example of atexit() in C language, Example#include #include void func1 (void) {    printf("Exit of function 1"); } void func2 (void) {   ...

Read More

C++ Program to Compute Combinations using Factorials

Samual Sam
Samual Sam
Updated on 11-Mar-2026 1K+ Views

The following is an example to compute combinations using factorials.Example#include using namespace std; int fact(int n) {    if (n == 0 || n == 1)    return 1;    else    return n * fact(n - 1); } int main() {    int n, r, result;    coutn;    coutr;    result = fact(n) / (fact(r) * fact(n-r));    cout

Read More

Write a power (pow) function using C++

Samual Sam
Samual Sam
Updated on 11-Mar-2026 2K+ Views

The power function is used to find the power given two numbers that are the base and exponent. The result is the base raised to the power of the exponent.An example that demonstrates this is as follows −Base = 2 Exponent = 5 2^5 = 32 Hence, 2 raised to the power 5 is 32.A program that demonstrates the power function in C++ is given as follows −Example#include using namespace std; int main(){    int x, y, ans = 1;    cout > x;    cout > y;    for(int i=0; i

Read More

Swapping two variable value without using third variable in C/C++

Samual Sam
Samual Sam
Updated on 11-Mar-2026 588 Views

The following is an example of swapping two variables.Example#include int main() {    int a, b;    printf("Enter the value of a : ");    scanf("%d", &a);    printf("Enter the value of b : ");    scanf("%d", &b);    a += b -= a = b - a;    printf("After Swapping : %d\t%d", a, b);    return 0; }OutputEnter the value of a : 23 Enter the value of b : 43 After Swapping : 4323In the above program, two variables a and b are declared and initialized dynamically at run time.int a, b; printf("Enter the value of a ...

Read More
Showing 2831–2840 of 5,961 articles
« Prev 1 282 283 284 285 286 597 Next »
Advertisements