Skip to content

Instantly share code, notes, and snippets.

@muaddib1971
Created May 15, 2024 03:02
Show Gist options
  • Save muaddib1971/f6cf7304f9abd7e02cc370ec3c979c79 to your computer and use it in GitHub Desktop.
Save muaddib1971/f6cf7304f9abd7e02cc370ec3c979c79 to your computer and use it in GitHub Desktop.
memory problems
#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;
}
#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;
}
#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;
}
#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