I try to understand something about the amount of memory allocated to the stack and to the heap. Suppose sizeof(char) = 1 byte, and sizeof(void *) = 4 byte. given the following code:
#include<stdio.h> #include<stdlib.h> #include<string.h> int main() { int i; char *str1 = "hello"; char str2[] = "hello"; char *str3 = (char*)malloc(strlen(str2)); //free code return 0; } We have been told that the amount of memory allocated to the heap is 5 bytes, and I understand that indeed this is the amount in the malloc (strlen(str2) = 5). But, what I don't understand is how the amount of memory allocated to the stack is 18 bytes? I thought that if they give us the information that a pointer size is 4 bytes, so we have 4 bytes for the pointer str1 and another 6 bytes for the array str2 (including the '/0'). What am I missing? where are the 18 bytes for the stack comes from? Thanks in advance for your help!
iandstr3?