Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 2317 of 2650
296 Views
C treats array parameter as pointers because it is less time consuming and more efficient. Though if we can pass the address of each element of the array to a function as argument but it will be more time consuming. So it’s better to pass the base address of first element to the function like:void fun(int a[]) { … } void fun(int *a) { //more efficient. ….. }Here is a sample code in C:#include void display1(int a[]) //printing the array content { int i; printf("Current content of the array is: "); for(i = 0; i < ... Read More
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
394 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
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
9K+ 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
7K+ Views
Passing an array by reference is a method of passing arrays to functions in C++ that allows the function to access and modify the original array without creating a copy. In this article, we will learn how to pass arrays by reference, the benefits of this approach, and provide examples. Passing an Array by Reference In the pass by reference approach, the address location of the first element of the array is passed to user defined functions. So, technically, we are passing the same array to that function without creating a copy. The changes made to the array ... Read More
6K+ Views
In C/C++, we usually use the sizeof operator to find the size of an array. However, once an array is passed to a function, its size is lost. So, how can we find the size of an array without using sizeof? For example, consider this array: int arr[] = {1, 2, 3, 4, 5}; Without using sizeof, we can use a loop to count the number of elements in the array. In this article, we'll show you different methods to find the size of an array in C or C++ without using sizeof, with clear and simple examples. ... Read More
870 Views
A dynamic 2D array is an 2D array in which the size of array is determined during runtime and stored using pointers. In this article, we will learn how to create a dynamic 2D array inside a class in C++. First of all, let's understand the problem statement. In this problem, you need to create a class that contains a dynamic 2D array as its data member. The memory allocation and deallocation must be handled using constructor and destructor. For example: // Create a class with dynamic 2D array ClassMatrix m(3, 4); // Output Matrix of size ... Read More
4K+ Views
A string in C++ is a group of characters written inside double quotes like "Hello" and characters are the single letters or symbols in a string. Converting a string to a char array means putting each character into a simple list (array) of characters. In this article, we will show you how to convert a string to a character array in C++. For example, if we have the string "Hello@TP", converting it to a char array means storing each character 'H', 'e', 'l', 'l', 'o', '@', 'T', and 'P' separately in an array.How to Convert a String into a Character ... Read More
