C++ Articles - Page 616 of 719

sqrt, sqrtl and sqrtf in C++

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

913 Views

In the cmath library of C++, there are different functions for getting the square root except from sqrt. The sqrt is used basically for double type input. The others are used for float, long type data etc. Let us see the usage of these functions.The sqrt() FunctionThis function is used for double type data. So this returns square root of type double. The syntax is like below.double sqrt(double argument)Example#include #include #include using namespace std; main() {    double x = 144.0;    double y = 180.0;    cout

abs(), labs(), llabs() functions in C/C++

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

214 Views

In the cstdlib library of C++, there are different functions for getting the absolute value except from abs. The abs are used basically for int type input in C, and int, long, long long in C++. The others are used for long, and long long type data etc. Let us see the usage of these functions.The abs() FunctionThis function is used for int type data. So this returns the absolute value of the given argument. The syntax is like below.int abs(int argument)Example#include #include #include using namespace std; main() {    int x = -145;    int y = 145;    cout

remainder() in C++

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

210 Views

Here we will see the functionality of remainder() method of C++. The remainder() function is used to compute the floating point remainder of numerator/denominator.So the remainder(x, y) will be like below.remainder(x, y) = x – rquote * yThe rquote is the value of x/y. This is rounded towards the nearest integral value. This function takes two arguments of type double, float, long double, and returns the remainder of the same type, that was given as argument. The first argument is numerator, and the second argument is the denominator.Example#include #include using namespace std; main() {    double x = ... Read More

wcstoll() function in C/C++

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

183 Views

The wcstoll() function is used to convert the wide character string to long long integers. It sets the pointer to point to the first character after the last one. The syntax is like below.long long wcstoll(const wchar_t* str, wchar_t** str_end, int base)This function takes three arguments. These arguments are like below −str: This is the starting of a wide string.str_end: The str_end is set by the function to the next character, after the last valid character, if there is any character, otherwise null.base: This specifies the base. The base values can be of (0, 2, 3, …, 35, 36)This function ... Read More

strtol() function in C++

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

353 Views

The strol() function is used to convert the string to long integers. It sets the pointer to point to the first character after the last one. The syntax is like below. This function is present into the cstdlib library.long int strtol(const char* str, char ** end, int base)This function takes three arguments. These arguments are like below −str: This is the starting of a string.str_end: The str_end is set by the function to the next character, after the last valid character, if there is any character, otherwise null.base: This specifies the base. The base values can be of (0, 2, ... Read More

ldexp() function in C/C++

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

207 Views

Here we will see what is the use of ldexp() method in C or C++. This function returns any variable x raise to the power of exp value. This takes two arguments x and exp.The syntax is like below.float ldexp (float x, int exp) double ldexp (double x, int exp) long double ldexp (long double x, int exp) double ldexp (T x, int exp)Now let us see one example to get a better idea.Example#include #include using namespace std; int main() {    double a = 10, res;    int exp = 2;    res = ldexp(a, exp); // Finds a*(2^exp)    cout

Preventing Object Copy in C++

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

292 Views

In C++, when classes are created, we can copy it using some copy constructor or assignment operator. In this section we will see, how to prevent object copy of a class in C++. To prevent object copy, we can follow some rules. These are like below.1. Creating private copy constructor and private assignment operator.Example#include using namespace std; class MyClass {    int x;    public:       MyClass() {          //non-parameterized constructor       }       MyClass(int y): x(y) {       }    private:       MyClass(const MyClass& obj) ... Read More

Advanced C++ with boost library

Samual Sam
Updated on 30-Jul-2019 22:30:26

1K+ Views

C++ boost libraries are widely useful library. This is used for different sections. It has large domain of applications. For example, using boost, we can use large number like 264 in C++.Here we will see some examples of boost library. We can use big integer datatype. We can use different datatypes like int128_t, int256_t, int1024_t etc. By using this we can get precision up to 1024 easily.At first we are multiplying two huge number using boost library.Example#include #include using namespace boost::multiprecision; using namespace std; int128_t large_product(long long n1, long long n2) {    int128_t ans = (int128_t) n1 * ... Read More

Object Slicing in C++

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

559 Views

Object slicing is used to describe the situation when you assign an object of a derived class to an instance of a base class. This causes a loss of methods and member variables for the derived class object. This is termed as information being sliced away. For example, class Foo {    int a; }; class Bar : public Foo {    int b; }Since Bar extends Foo, it now has 2 member variables, a and b. So if you create a variable bar of type Bar and then create a variable of type Foo and assign bar, you'll lose ... Read More

transform() in C++

Samual Sam
Updated on 30-Jul-2019 22:30:26

3K+ Views

The transform function is present in the C++ STL. To use it, we have to include the algorithm header file. This is used to perform an operation on all elements. For an example if we want to perform square of each element of an array, and store it into other, then we can use the transform() function.The transform function works in two modes. These modes are −Unary operation modeBinary operation modeUnary Operation ModeIn this mode the function takes only one operator (or function) and convert into output.Example#include #include using namespace std; int square(int x) {    //define square ... Read More

Advertisements