Created
September 28, 2019 02:29
-
-
Save RolandWarburton/fe8f7cd39237be587f182db38f8adfe3 to your computer and use it in GitHub Desktop.
realloc arrays 2. electric boogaloo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main(int argc, char const *argv[]) | |
{ | |
int *cc = new int[20]; | |
int size = 0; | |
for (size_t i = 0; i < 5; i++) | |
{ | |
cout << "enter number: "; | |
cin >> cc[i]; | |
size++; | |
} | |
cc = (int *)realloc(cc, sizeof(int) * size); | |
for (size_t i = 0; i < size; i++) | |
{ | |
cout << cc[i]; | |
} | |
cout << "\n"; | |
system("pause"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment