C語言day07-01數(shù)組-內(nèi)存存儲(chǔ)細(xì)節(jié)

pragma mark 數(shù)組-內(nèi)存存儲(chǔ)細(xì)節(jié)

pragma mark 概念

pragma mark 代碼

#include <stdio.h>
int main()
{
    // 變量在內(nèi)存中的存儲(chǔ)
    // 由于變量的內(nèi)存尋址是從大到小,所以存儲(chǔ)數(shù)據(jù)時(shí)會(huì)從高字節(jié)
    int num = 10;   // 0000 0000 0000 0000 0000 0000 0000 1010
#pragma mark 數(shù)組的內(nèi)存細(xì)節(jié)
    /*
     // 注意:數(shù)組的存儲(chǔ)和變量有點(diǎn)不一樣,數(shù)組存儲(chǔ)元素, 是從所占用的低字節(jié)開始存儲(chǔ)
    char charValue[4] = {'l','y','h','s'};
//     charValue[0] = 0x7fff5fbff804
//     charValue[1] = 0x7fff5fbff805
//     charValue[2] = 0x7fff5fbff806
//     charValue[3] = 0x7fff5fbff807
    printf("charValue[0] = %p\n",&charValue[0]);
    printf("charValue[1] = %p\n",&charValue[1]);
    printf("charValue[2] = %p\n",&charValue[2]);
    printf("charValue[3] = %p\n",&charValue[3]);

    // &charValue == &charValue[0] == charValue
    printf("charValue = %p\n",&charValue);
    // 其實(shí)數(shù)組名就是數(shù)組的地址
    printf("charValue = %p\n",charValue);
     */
    
    // 0000 0000 0000 0000 0000 0000 0000 0101
    // 0000 0000 0000 0000 0000 0000 0000 0110

    int number[2] = {5,6};
    
    return 0;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容