Initial commit
This commit is contained in:
BIN
Final/FinalCode/heap/a.exe
Normal file
BIN
Final/FinalCode/heap/a.exe
Normal file
Binary file not shown.
25
Final/FinalCode/heap/heapmem.c
Normal file
25
Final/FinalCode/heap/heapmem.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
void print(int *i) {
|
||||
printf("The location of i: %p\n", i);
|
||||
int *k = (int *)malloc(sizeof(int));
|
||||
printf("The location of k: %p\n", k);
|
||||
}
|
||||
|
||||
int main() {
|
||||
int *i = malloc(sizeof(int));
|
||||
*i = 100;
|
||||
printf("The first variable on the heap: %p\n", i);
|
||||
int *ptr;
|
||||
{
|
||||
int *j = malloc(sizeof(int));
|
||||
ptr = j;
|
||||
*j = 200;
|
||||
printf("The first location of j: %p\n", j);
|
||||
}
|
||||
printf("The value of j out of its scope: %d\n", *ptr);
|
||||
printf("The new location of j: %p\n", ptr);
|
||||
|
||||
print(i);
|
||||
}
|
||||
|
Reference in New Issue
Block a user