Found 33676 Articles for Programming

What exactly is nullptr in C++?

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

337 Views

In this section we will see the nullptr in C++. The nullptr denotes the pointer literals. It is a prvalue of type std::nullptr_t. It has implicit conversion property from nullptr to null pointer value of any pointer type and any pointer to member type. Let us see one program, to understand this concept.Example#include using namespace std; int my_func(int N){ //function with integer type parameter    cout

How do I convert between big-endian and little-endian values in C++?

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

6K+ Views

Here we will see how to convert Little endian value to Big endian or big endian value to little endian in C++. Before going to the actual discussion, we will see what is the big endian and the little endian?In different architectures, the multi-byte data can be stored in two different ways. Sometimes the higher order bytes are stored first, in that case these are known as big endian, and sometimes the lower order bytes are stored first, then it is called little endian.For example, if the number is 0x9876543210, then the big endian will be −The little endian will ... Read More

When should I write the keyword 'inline' for a function/method in C++?

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

171 Views

In C++, the inline keyword is used in different places. To create inline variables, or inline namespace, and as well as to create inline methods or functions.C++ inline function is powerful concept that is commonly used with classes. If a function is inline, the compiler places a copy of the code of that function at each point where the function is called at compile time.Any change to an inline function could require all clients of the function to be recompiled because compiler would need to replace all the code once again otherwise it will continue with old functionality.To inline a ... Read More

Is there a difference between copy initialization and direct initialization in C++?

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

3K+ Views

The Copy initialization can be done using the concept of copy constructor. As we know that the constructors are used to initialize the objects. We can create our copy constructor to make a copy of some other object, or in other words, initialize current object with the value of another object. On the other hand, the direct initialization can be done using assignment operation.The main difference between these two types of initialization is that the copy initialization creates a separate memory block for the new object. But the direct initialization does not make new memory space. It uses reference variable ... Read More

What is the effect of extern “C” in C++?

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

3K+ Views

The extern “C” keyword is used to make a function name in C++ have the C linkage. In this case the compiler does not mangle the function. Let us see what is the mangling in C++ first, then we can discuss about the extern “C” keyword.In C++ we can use the function overloading feature. Using this feature, we can create functions with same name. The only difference is the type of the arguments, and the number of arguments. The return type is not considered here. Now the question comes how the C++ distinguishes overloaded functions in object code?In the object ... Read More

What is the difference between const int*, const int * const, and int const *?

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

555 Views

Here we will see some different types of variable declaration based on integer pointers integer constants and the integer constant pointers.To determine them we will use the Clockwise/Spiral Rule. By discussing the terms, we can understand the rules also.The const int *. This is used to tell the compiler that this is a pointer type variable, and this can store address of some constant int. The Clock rule is saying like this −Now the another one is const int * const. This is used to denote that this is one constant pointer variable, which can store the address of another ... Read More

What is the most effective way for float and double comparison in C/C++?

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

7K+ Views

Here we will see how to compare two floating point data or two double data using C or C++. The floating point / double comparison is not similar to the integer comparison.To compare two floating point or double values, we have to consider the precision in to the comparison. For example, if two numbers are 3.1428 and 3.1415, then they are same up to the precision 0.01, but after that, like 0.001 they are not same.To compare using this criteria, we will find the absolute value after subtracting one floating point number from another, then check whether the result is ... Read More

What's the best way to trim std::string in C++?

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

10K+ Views

Here we will see how to trim the strings in C++. The trimming string means removing whitespaces from left and right part of the string.To trim the C++ string, we will use the boost string library. In that library, there are two different methods called trim_left() and trim_right(). To trim string completely, we can use both of them.Example#include #include using namespace std; main(){    string myStr = " This is a string ";    cout

What is a null-terminated string in C/C++?

Tapas Kumar Ghosh
Updated on 13-Jun-2025 14:11:53

11K+ Views

In C, the strings are basically array of characters. In C++ the std::string is an advancement of that array. There are some additional features with the traditional character array. The null terminated strings are basically a sequence of characters, and the last element is one null character (denoted by '\0'). When we write some string using double quotes ("..."), then it is converted into null terminated strings by the compiler. The size of the string may smaller than the array size, but if there are some null character inside that array, that will be treated as the end of that ... Read More

The best way to hide a string in binary code in C++?

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

644 Views

Here we will see how to hide some string into some binary code (Here binary code is represented in hexadecimal number).The approach is very simple. We can use the string stream to convert decimal number to hexadecimal numbers. Now from the string, we will read each character, and take its ASCII value, these ASCII values are converted into hexadecimal values. Then we can print them one by one.Example#include #include using namespace std; string dec_to_hex(int decimal){ //function is used to convert decimal to hex    stringstream my_ss;    my_ss

Advertisements