Found 7401 Articles for C++

What does “dereferencing” a pointer mean in C/C++?

Samual Sam
Updated on 07-Nov-2023 20:34:31

20K+ Views

Dereferencing is used to access or manipulate data contained in memory location pointed to by a pointer. *(asterisk) is used with pointer variable when dereferencing the pointer variable, it refers to variable being pointed, so this is called dereferencing of pointers. int main() {    int a = 7, b ;    int *p; // Un-initialized Pointer    p = &a; // Stores address of a in ptr    b = *p; // Put Value at ptr in b }Here, address in p is basically address of a variable.

How does “void *” differ in C and C++?

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

423 Views

In this section we will see what are the differences between void pointer in C and void pointer in C++. They are both void pointers but in C a void pointer can be assigned to any pointer type, but in C++, we cannot do that. In C++ we have to explicitly typecast for assigning.In the following example these lines can be executed when we are writing some codes in C.void *p; int *int_ptr = p;This will work fine in C. Now if we use malloc() to allocate some memory spaces, we can use the explicit typecast, but if we do ... Read More

Data type of character constants in C and C++

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

645 Views

In C++ the size of the character constants is char. In C the type of character constant is integer (int). So in C the sizeof(‘a’) is 4 for 32bit architecture, and CHAR_BIT is 8. But the sizeof(char) is one byte for both C and C++.Example Live Demo#include main() {    printf("%d", sizeof('a')); }Output4Example Live Demo#include using namespace std; main() {    cout

Can we use function on left side of an expression in C and C++?

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

248 Views

In C we cannot use function name at the left hand side of an expression. In C++ we can use it like that. This can be done by some function which returns some reference variable.A C++ function can return a reference in a similar way as it returns a pointer.When a function returns a reference, it returns an implicit pointer to its return value. This way, a function can be used on the left side of an assignment statement. For example, consider this simple program −Example Live Demo#include #include using namespace std; double vals[] = {10.1, 12.6, 33.1, 24.1, ... Read More

C++ Array of Strings

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

18K+ Views

In this section we will see how to define an array of strings in C++. As we know that in C, there was no strings. We have to create strings using character array. So to make some array of strings, we have to make a 2-dimentional array of characters. Each rows are holding different strings in that matrix.In C++ there is a class called string. Using this class object we can store string type data, and use them very efficiently. We can create array of objects so we can easily create array of strings.After that we will also see how ... Read More

Complex numbers in C++

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

8K+ Views

In this section we will see how to create and use complex numbers in C++. We can create complex number class in C++, that can hold the real and imaginary part of the complex number as member elements. There will be some member functions that are used to handle this class.In this example we are creating one complex type class, a function to display the complex number into correct format. Two additional methods to add and subtract two complex numbers etc.Example Live Demo#include using namespace std; class complex {    int real, img;    public:       complex() {   ... Read More

Builtin functions of GCC compiler in C++

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

397 Views

In the GCC compiler there are some builtin functions. These functions are like below.Function _builtin_popcount(x)This builtin function is used to count the number of 1s in an integer type data. Let us see an example of _builtin_popcount() function.Example Live Demo#include using namespace std; int main() {    int n = 13; //The binary is 1101    cout

Wide char and library functions in C++

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

3K+ Views

In this section we will see what is the wide character in C++. We will also see some functions that are used to handle wide characters.Wide characters are similar to character datatype. The main difference is that char takes 1-byte space, but wide character takes 2-bytes (sometimes 4-byte depending on compiler) of space in memory. For 2-byte space wide character can hold 64K (65536) different characters. So the wide char can hold UNICODE characters. The UNICODE values are international standard which allows for encoding for characters virtually for any character of any language.Example Live Demo#include using namespace std; int main() { ... Read More

Conversion constructor in C++?

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

661 Views

In this section we will see what is the conversion constructor in C++ class. A constructor is a special type of function of class. It has some unique property like, its name will be same as class name, it will not return any value etc. The constructors are used to construct objects of a class. Sometimes constructors may take some arguments, or sometimes it does not take arguments.When a constructor takes only one argument then this type of constructors becomes conversion constructor. This type of constructor allows automatic conversion to the class being constructed.Example Live Demo#include using namespace std; class my_class{ ... Read More

Type difference of character literals in C and C++

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

520 Views

In C++ the size of the character constants is char. In C the type of character constant is integer (int). So in C the sizeof(‘a’) is 4 for 32bit architecture, and CHAR_BIT is 8. But the sizeof(char) is one byte for both C and C++.Example Live Demo#include main() {    printf("%d", sizeof('a')); }Output4Example Live Demo#include using namespace std; main() {    cout

Advertisements