作者 主題: 問題  (閱讀 5037 次)

0 會員 與 1 訪客 正在閱讀本文。

gcobt44292

  • 可愛的小學生
  • *
  • 文章數: 11
    • 檢視個人資料
問題
« 於: 2013-12-17 21:07 »
#include<stdio.h>
#include<stdlib.h>
#define size 20
size_t getsize(float *ptr);
int main(void)
{
float array[size];
printf("the number of bytes in the array is %u""\nthe number of bytes returned bt getsize is %u\n",sizeof(array),getsize(array));
}//end main
size_t getsize(float *ptr)
{
return sizeof(ptr);
}
運算出來the number of bytes in the array is 80為什麼, float為啥是4  float array[size]--4*20

另外%p是將16禁制列印出來?
« 上次編輯: 2013-12-17 21:10 由 gcobt44292 »

Yamaka

  • 俺是博士!
  • *****
  • 文章數: 4913
    • 檢視個人資料
    • http://www.ecmagic.com
Re: 問題
« 回覆 #1 於: 2013-12-17 21:28 »
#include<stdio.h>
#include<stdlib.h>
#define size 20
size_t getsize(float *ptr);
int main(void)
{
float array[size];
printf("the number of bytes in the array is %u""\nthe number of bytes returned bt getsize is %u\n",sizeof(array),getsize(array));
}//end main
size_t getsize(float *ptr)
{
return sizeof(ptr);
}
運算出來the number of bytes in the array is 80為什麼, float為啥是4  float array[size]--4*20

另外%p是將16禁制列印出來?

加下面這兩行下去跑,看結果應該就能了解了

代碼: [選擇]
printf("float size: %lu, float* size: %lu\n",sizeof(float), sizeof(float*));
printf("char size: %lu, char* size: %lu\n",sizeof(char), sizeof(char*));

gcobt44292

  • 可愛的小學生
  • *
  • 文章數: 11
    • 檢視個人資料
Re: 問題
« 回覆 #2 於: 2013-12-17 21:57 »
不太懂 size不是設20嗎float*size=4?? 能稍加解釋一下嗎
課本解釋說:array宣告20元素,這台電腦float變數占用4位元組?

Yamaka

  • 俺是博士!
  • *****
  • 文章數: 4913
    • 檢視個人資料
    • http://www.ecmagic.com
Re: 問題
« 回覆 #3 於: 2013-12-17 23:03 »
不太懂 size不是設20嗎float*size=4?? 能稍加解釋一下嗎
課本解釋說:array宣告20元素,這台電腦float變數占用4位元組?

上面那兩行跑出來的結果還看不懂嗎?! = =||

gcobt44292

  • 可愛的小學生
  • *
  • 文章數: 11
    • 檢視個人資料
Re: 問題
« 回覆 #4 於: 2013-12-17 23:21 »
喔~~懂了 是float浮點數 是4?

gcobt44292

  • 可愛的小學生
  • *
  • 文章數: 11
    • 檢視個人資料
Re: 問題
« 回覆 #5 於: 2013-12-18 01:13 »
還是不太懂 ???