Found 7346 Articles for C++

C++ Program to Implement Hash Tables chaining with Singly Linked Lists

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

3K+ Views

A hash table is a data structure which is used to store key-value pairs. Hash function is used by hash table to compute an index into an array in which an element will be inserted or searched.This is a C++ program to Implement Hash Tables chaining with singly linked lists.AlgorithmFor insert:Begin    Declare Function Insert(int k, int v)       int hash_v = HashFunc(k)       HashTableEntry* p = NULL       HashTableEntry* en = ht[hash_v]       while (en!= NULL)          p = en          en= en->n     ... Read More

C++ Program to Implement Hash Tables Chaining with List Heads

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

461 Views

A hash table is a data structure which is used to store key-value pairs. Hash function is used by hash table to compute an index into an array in which an element will be inserted or searched.This is a C++ Program to Implement Hash Tables Chaining with List Heads.AlgorithmFor insert:Begin    Declare function Insert(int k, int v)       int hash_v = HashFunc(k)       if (ht[hash_v] == NULL)          ht[hash_v] = new ListHead(k, v)       else          ListHead *en = ht[hash_v]          while (en->n != NULL) ... Read More

How do conversion operators work in C++?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

195 Views

In this article, we will see what is the conversion operator in C++. C++ supports object-oriented design. So we can create classes of some real-world objects as concrete types.Sometimes we need to convert some concrete type objects to some other type objects or some primitive datatypes. To make this conversion we can use conversion operator. This is created like operator overloading function in class.In this example, we are taking a class for complex numbers. It has two arguments real and imaginary. When we assign the object of this class into some double type data, it will convert into its magnitude ... Read More

Global memory management in C++ : Stack or Heap?

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

2K+ Views

Stack and heap are used to store variables during the execution of the program and it also get destroyed.Global data structures or global variables are not consumed by stack or heap. They basically allocated in a fixed memory block, which remains unchanged.int a[10]; // located in a fixed memory block int main() {    int main() {       float *ptr = (int *)malloc(sizeof(float)10.0)); //use heap.    } }

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

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

21K+ 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

444 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

702 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

264 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

Advertisements