Directory Listing | |
---|---|
calloc.c
|
|
hello_world.c
|
|
makefile
|
|
malloc_free.c
|
|
new_delete.cpp
|
|
realloc.c
|
|
string_ex1.c
|
|
string_ex2.c
|
|
struct_ex1.c
|
|
struct_ex1.cpp
|
|
struct_ex2.c
|
|
struct_func_ex.c
|
|
struct_func_ex.cpp
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>
#include <stdlib.h>
int main() {
//Allocate memory. I think 10 would be fine.
int* a = (int *) malloc(sizeof(int) * 10);
int i;
//Actually... I want 15...
a = (int *) realloc(a, sizeof(int) * 15);
//Put values in the array
for (i = 0; i < 15; i++)
a[i] = i;
//Print out the values in the array
for (i = 0; i < 15; i++)
printf("%d ", a[i]);
printf("\n");
//Free memory
free(a);
}