Considering the following code fragment:
#include<stdio.h>
#include <stdlib.h>
int base = 0;
static int bonus;
int* demage (int dmg) {
int* ptr = (int*) malloc(sizeof(int));
static int constant = 1;
*ptr = dmg + constant;
return ptr;
}
int main() {
int HP = 0;
int* dm;
base = 30;
bonus = 20;
for(int i=1; i<4; i++) { HP += i * base; }
dm = demage(10);
HP += bonus - *dm;
printf("Total HP: %i", HP);
return 0;
}
Please indicate which memory
segment each of the following values is allocated
to.
The genral rule is that local variables are always stored in stack memory and static, global and dynamic variabes use heap memory location.
So in the above code
Get Answers For Free
Most questions answered within 1 hours.