Commit f191efe7 authored by Dong Hung Pham's avatar Dong Hung Pham 🤡
Browse files

updated prak1

parents
#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>
static int *ptr;
int global1 = 10;
int global2 = 20;
int global3 = 30;
void TestFunc(void)
{
int lokal1 = 1;
int lokal2 = 2;
int lokal3 = 3;
ptr = &lokal1;
int *heap1 = new int;
int *heap2 = new int;
int *heap3 = new int;
printf("Test Func \n");
printf("Stack[0]: %p\nStack[1]: %p\nStack[2]: %p\nHeap[n]: %p\nHeap[n+1]: %p\nHeap[n+2]: %p\n", &lokal1, &lokal2, &lokal3, heap1, heap2, heap3);
printf("Adress Function: %p\n",&TestFunc);
delete heap1,heap2,heap3;
}
int main()
{
struct rlimit rl;
int lokal1 = 1;
int lokal2 = 2;
int lokl2 = 2;
int lokal3 = 3;
int *heap1 = new int;
int *heap2 = new int;
int *heap3 = new int;
printf("Main \n");
printf("Global 1: %p\nGlobal 2: %p\nGlobal 3: %p\n",&global1,&global2,&global3);
printf("Stack[0]: %p\nStack[1]: %p\nStack[2]: %p\nHeap[n]: %p\nHeap[n+1]: %p\nHeap[n+2]: %p\n", &lokal1, &lokal2, &lokal3, heap1, heap2, heap3);
TestFunc();
printf ("test : %p\n" ,ptr);
printf("Size: %d\n", (int)((&lokal1) - ptr));
printf("Adress main: %p\n",&main);
getrlimit (RLIMIT_STACK, &rl);
printf ("The current maximum size of stack is %lu.\n", (int)rl.rlim_cur);
printf ("The hard limit of stack is %lu.\n", (int)rl.rlim_max);
getrlimit (RLIMIT_DATA, &rl);
printf ("The current maximum size of heap is %lu.\n", (int)rl.rlim_cur);
printf ("The hard limit of heap is %lu.\n", (int)rl.rlim_max);
// delete heap1,heap2,heap3;
return 0;
}
/** Antwort:
Stack wacht nach unter wahrend Heap wach nach oben .
example :
stack ----> High adress
|
|
|
v
^
|
|
|
heap ----> Low adress
wieviel Speicher wird für einen
Aufruf von function : es ist adress der 1st lokal var von main subtrahiert adress 1st lokal var von function
*/
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment