Created
May 15, 2024 03:02
-
-
Save muaddib1971/f6cf7304f9abd7e02cc370ec3c979c79 to your computer and use it in GitHub Desktop.
memory problems
This file contains hidden or 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
#define size 30 | |
#include <cstdlib> | |
void allocate_array(int** array) { *array = new int[size]; } | |
int main() { | |
int* array; | |
allocate_array(&array); | |
int count; | |
for (count = 0; count < size; ++count) { | |
array[count] = count; | |
} | |
delete array; | |
return EXIT_SUCCESS; | |
} |
This file contains hidden or 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
#define size 30 | |
#include <cstdlib> | |
void allocate_array(int** array) { *array = new int[size]; } | |
int main() { | |
int* array; | |
allocate_array(&array); | |
int count; | |
for (count = 0; count < size; ++count) { | |
array[count] = count; | |
} | |
// delete array; | |
return EXIT_SUCCESS; | |
} |
This file contains hidden or 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 <cstdlib> | |
#include <iostream> | |
#include <vector> | |
#define size 6 | |
int main() { | |
std::vector<int> ints{1, 2, 5, 7, 9}; | |
for (int count = 0; count < size; ++count) { | |
std::cout << ints[count] << std::endl; | |
} | |
return EXIT_SUCCESS; | |
} |
This file contains hidden or 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> | |
#include <vector> | |
#include <cstdlib> | |
const int size = 3; | |
int main() { | |
int array[size]; | |
std::cout << array[0] << std::endl; | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment