Found 33676 Articles for Programming

expm1() in C++

Chandu yadav
Updated on 25-Jun-2020 10:11:08

68 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 Live Demo#include #include using namespace std; int main() {    int x = 10;    float y = 8.28;    cout

log1p() in C++

Arjun Thakur
Updated on 25-Jun-2020 10:11:47

123 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 Live Demo#include #include using namespace std; int main() {    int ... Read More

frexp() in C++

Ankith Reddy
Updated on 25-Jun-2020 10:12:32

123 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

Which is faster between C++ and C#?

Chandu yadav
Updated on 30-Jul-2019 22:30:23

283 Views

C++ is a middle-level language. It was developed by Bjarne Stroustrup in 1979. It is just an enhancement to C language and an object-oriented language. C# is modern and object-oriented language developed by Anders Hejlsberg. It is a part of the .NET framework. It is designed for Common Language Infrastructure (CLI). It is also a popular language. Difference between C++ and C# Both languages are object-oriented languages. C++ has low level of abstraction while C# has high level of abstraction. In C++, the program can be coded for any platform while in C#, the program is targeted towards windows ... Read More

How to catch all the exceptions in C++?

Tapas Kumar Ghosh
Updated on 02-Jun-2025 14:26:55

11K+ Views

Exceptions are problems that arise at the time of execution of a program. They are events that are thrown at runtime. They protect the code and allow the program to run even after an exception is thrown. Exception handling is used to handle the exceptions. Catching All Exceptions To handle all exceptions in C++, use try and catch blocks. Write the code that may generate exceptions inside a try block (try { ... }), and handle or print the exception inside a corresponding catch block (catch(...) { ... }). Syntax Following is the syntax of catch block in C++: ... Read More

How to throw a C++ exception?

Chandu yadav
Updated on 25-Jun-2020 10:15:04

296 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 Live Demo#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

Left Shift and Right Shift Operators in C/C++

Tapas Kumar Ghosh
Updated on 02-May-2025 18:02:48

2K+ Views

Both the left shift and right shift are known as bitwise shift operators. These operators are useful for working with binary integers by shifting the bits to the left or right. Below is the mathematical representation of the left and right shift operators: // left shift operator x > n means (x/2n) What is Left Shift Operator? In the left shift operator, the left operand value is moved left by the number of bits specified by the right operand. Syntax The basic syntax of left shift operator as follows:

Purpose of Unions in C/ C++

Ankith Reddy
Updated on 25-Jun-2020 10:04:03

4K+ Views

Union is a user-defined datatype. All the members of union share same memory location. Size of union is decided by the size of largest member of union. If you want to use same memory location for two or more members, union is the best for that.Unions are similar to structures. Union variables are created in same manner as structure variables. The keyword “union” is used to define unions in C language.Here is the syntax of unions in C language, union union_name {    member definition; } union_variables;Here, union_name  − Any name given to the union.member definition  − Set of member ... Read More

C++11 features in Visual Studio 2015

George John
Updated on 30-Jul-2019 22:30:23

379 Views

C++11 is a version of standard C++ language. It was approved by International Organization for Standardization (ISO) on 12 August 2011 then C++14 and C++17. C++11 makes several additions to the core language. Visual C++ implements the vast majority of features in C++11. Some of the following C++11 features in Visual Studio 2015 − nullptr − In the previous nullptr, zero used to be the value and it had a drawback ofimplicit conversion to integral value. The null pointer literal is represented by std::nullptr_t. In this nullptr, no implicit conversion exists. Lambdas − The lambda expression allows to ... Read More

How do malloc() and free() work in C/C++?

Chandu yadav
Updated on 28-Apr-2025 18:21:44

2K+ Views

Both malloc() and free() are used to manage memory at runtime. The malloc() is very useful because it allocates memory based on the program needs, while free() releases the memory. But the free() can lead to memory leakage, which is one of its disadvantages. What is malloc()? The function malloc() is used to allocate the requested size of bytes and it returns a pointer to the first byte of allocated memory. It returns null pointer, if it fails. Syntax Following is the basic syntax of malloc(): pointer_name = (cast-type*) malloc(size); Here, pointer_name : Any ... Read More

Advertisements