Found 7197 Articles for C++

C++ Program to Implement Forward_List in STL

Farhan Muhamed
Updated on 06-May-2025 18:20:36

263 Views

Forward List is a type of singly linked list available in the C++ STL (Standard Template Library). In this artcile, we will learn how to use forward_list from C++ STL library. What is Forward List? Forward list is a linear data structure which allows traversal only in one direction. It is similar to a singly linked list where each element points to the next element and moves in forward direction. It supports operations like insertion, deletion, and traversal from the beginning to end but not in reverse direction. The insertion and deletion operations are comparatively very fast in ... Read More

C++ Program to Implement Deque in STL

Farhan Muhamed
Updated on 06-May-2025 18:20:01

440 Views

Deque or Double Ended Queue is a special type of queue where we can insert and delete elements from both front and back. In this article, we will learn how to use deque from C++ STL (Standard Template Library). What is Deque? Deque is a linear data structure in which the insertion and deletion operations can be performed at both the ends (front and rear). Meaning, the data can be inserted at both front and rear positions and can be deleted from both front and rear positions. This gives more flexibility compared to a normal queue which supports only ... Read More

Binary Search functions in C++ STL

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

1K+ Views

Binary search is a search algorithm that finds the position of a target value within a sorted array. Binary search compares the target value to the middle element of the sorted array. The time complexity of binary search is O(1). This is a C++ program in which we implement various. Binary Search functions in C++ STLAlgorithmBegin    Initialize the vector of integer values.    The functions are used here:    binary_search(start_pointer, end_pointer, value) = Returns true if the value present in array otherwise    false.    lower_bound(start_pointer, end_pointer, value) = Returns pointer to “position of value” if container ... Read More

4 Dimensional Array in C/C++

Farhan Muhamed
Updated on 29-May-2025 19:12:08

1K+ Views

4 Dimensional ArrayThe 4 dimensional array is an array of 3 dimensional arrays. Each 3 dimensional array is an array of 2 dimensional arrays and each 2 dimensional array is an array of 1 dimensional arrays. In this article, we will learn all about 4 dimensional arrays, how to create them and how to access their elements with examples in both C and C++. Syntax to Create a 4D Array Following is the syntax for declaring a 4 dimensional array in C/C++: datatype array_name[dimension1][dimension2][dimension3][dimension4]; // Example int arr[3][2][3][4]; Example of a 4 Dimensional Array The ... Read More

Why C/C++ array index starts from zero?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

755 Views

As Array index starts with 0, so a[i] can be implemented as *(a + i).If Array index starts with 1 then a[i] will be implemented as *(a+i-1) which will be time consuming during compilation and the performance of the program will also be effected.So, it is better to start index of the array from 0.A simple program of array is given -Example Codeint main() {    int array[5] = {7, 7, 7, 6, 6};    for (int i = 0; i < 5; i++)       cout

An Uncommon representation of array elements in C/C++

Nitya Raut
Updated on 30-Jul-2019 22:30:25

127 Views

This is a simple C++ program of an uncommon representation of array elements.#include using namespace std; int main() { int array[5] = {7,7,7, 6, 6}; for (int i = 0; i < 5; i++) cout

How to create a dynamic array of integers in C++ using the new keyword

Farhan Muhamed
Updated on 02-Jun-2025 19:34:43

11K+ Views

Dynamic arrays are a type of array that can change their size when new elements are added or removed. They are created using pointers and memory management operators like new and delete. In this article, we will learn how to create and use a dynamic array in C++. What is Dynamic Array? A dynamic array is an array that can change its size during runtime. This is different from a static arrays, which have a fixed size determined by the programmer at compile time. Dynamic arrays are used when the size of the array is not known at compile ... Read More

Passing Arrays to Function in C++

Farhan Muhamed
Updated on 02-Jun-2025 19:35:02

380 Views

In this article, we will learn different ways to pass arrays to functions in C++ and how to work with them effectively. Passing Arrays to Functions Here are list of approaches to pass arrays to functions in C++ that will be discussed in this article along with examples: As a Sized Array As an Unsized Array As a Pointer (Pass by Pointer) As a Reference (Pass by Reference) As a Sized Array This method passes an array to a ... Read More

How to initialize a dynamic array in C++?

Farhan Muhamed
Updated on 16-Jul-2025 16:01:28

3K+ Views

Dynamic arrays are a type of array that can grow or shrink their size as elements are added or removed. They are created using pointers and memory management functions such as new and delete. In this article, we will learn different ways to initialize a dynamic arrays in C++. Here is the list of approaches to initialize a dynamic array in C++: Using new and () Using new and {} Using Loop for Custom Initialization Initializing Dynamic Arrays Using new and () This ... Read More

How to use std::sort to sort an array in C++

Farhan Muhamed
Updated on 29-May-2025 19:13:01

8K+ Views

Sorting of an array refer to the process of arranging the elements of the array in ascending or descending order. In this article, we will learn how to use the std::sort function from the C++ STL library to sort an array. In this problem, you are given an array of integers, and you need to arrange the elements in ascending order using std::sort. For example: // Input array int arr[] = {5, 2, 9, 1, 5, 6}; // Output {1, 2, 5, 5, 6, 9} // Explanation: The array is sorted in ascending order. C++ ... Read More

Advertisements