mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 09:41:36 +00:00
Remove undefined behavior (#2332)
This commit is contained in:
parent
a0b6af4534
commit
21c4be4779
@ -449,7 +449,8 @@ int main (int argc, char** argv)
|
||||
int size = 10;
|
||||
int *my_arr = malloc(sizeof(int) * size);
|
||||
// Add an element to the array
|
||||
my_arr = realloc(my_arr, ++size);
|
||||
size++;
|
||||
my_arr = realloc(my_arr, sizeof(int) * size);
|
||||
my_arr[10] = 5;
|
||||
|
||||
// Dereferencing memory that you haven't allocated gives
|
||||
|
Loading…
Reference in New Issue
Block a user