increase_size

Run Settings
LanguageC++
Language Version
Run Command
// Increasing the array size #include <iostream> using namespace std; int main() { cout << "Enter the array size"; int n; cin >> n; int *arr1 = new int[n] for(int i=0; i<n; ++i){ cout << "Enter element"; cin >> *(arr1+i); } cout << "Do you wanna increase the size of the array: (true/false)"; // for bool in c use <stdbool.h> c++ has bool datatype independently bool val; cin >> val; cout << "Enter the new size of the array: "; int n1; cin >> n1; int *arr2 = new int[n1]; memcpy(arr2,arr1,n); // delete operator deallocates a block of memory allocated in heap delete []arr1; arr1 = arr2; // now arr1 also pointing to same array in heap; // removing arr2 pointing to array arr2 = nullptr; return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines