參考下面的鏈接說明如何找到機器堆棧是否在內存中增長...我想知道下面是否是正確的方法來查找機器的堆在記憶中增長或減少。查找堆是否長大
How would you find out if a machine’s stack grows up or down in memory? (JAVA)
我的代碼
void findHeapDirection(int *a) {
int *b;
b = (int*)malloc(sizeof(b));
printf("\naddress of a %x",a);
printf("\naddress of b %x",&b);
if(b > a)
printf("\n>>heap grows up");
else
printf("\n>>heap grows down");
free(b);
}
,並呼籲像這樣
int *a;
a = (int*)malloc(sizeof(a));
findHeapDirection(a);
free(a);
這此功能爲我的機器上輸出..
address of a 5417b0
address of b 28ff14
>>heap grows up
或者這個問題不明確,因爲堆永遠不能向下增長?
謝謝羅伯特。這有幫助。 ! – Jiten