close
Blogtrottr
批踢踢實業坊 Examination 板
 
Re: [課業] 程式語言兩題
Jul 28th 2013, 18:40, by Mayinggo

作者Mayinggo (馬贏狗)

看板Examination

標題Re: [課業] 程式語言兩題

時間Sun Jul 28 18:40:20 2013

※ 引述《Mayinggo (馬贏狗)》之銘言: : 1.已知陣列M[15][12],每個元素4bytes。M[5][5]位址=13244868,行為主儲存模式, : 則M結束位置為... : 我是算13244868+((11-5)*15+(14-5))*4=13245264 : 可是書本上說還要加3 所以不清楚加3的原因為何 : 2.#include <stdio.h> : #include <stdlib.h> : #include <string.h> : union grade{ : char course[5]; : int score; : }Bob; : void printBob(void){ : printf("Bob科目=%s\n",Bob.course); : printf("Bob成績=%d\n",Bob.score); : } : int main(void){ : Bob.score=98; : strcpy(Bob.course,"數學"); : printBob(); : strcpy(Bob.course,"數學"); : Bob.score=98; : printBob(); : system("PAUSE"); return 0; : } : output是Bob科目=數學 : Bob成績=-943798596 : Bob科目=b : Bob成績=98 : 那個-943798596和b是怎麼形成的不太清楚 : 還請會的大大賜教 隨便改幾個數字的結果 結果output好像是第一個Bob科目的文字一改 對應的成績也就會跟著變動 第一個Bob.score=98的結果跑不出來 第二個Bob.score=98的數字一改 對應的科目字元也會跟著變動 好像變成ASCII轉換 後面的結果會覆蓋前面的結果 如果上述改成Struct 那就等於科目 數學 成績98跑兩次 因為各自擁有記憶體空間 所以不受影響 只是用Union的話 共用記憶體空間5byte 所以才變成跑不出要的結果? 不知道是不是這個意思 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.242.11.49

This entry passed through the Full-Text RSS service — if this is your content and you're reading it on someone else's site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers. Five Filters recommends: 'You Say What You Like, Because They Like What You Say' - http://www.medialens.org/index.php/alerts/alert-archive/alerts-2013/731-you-say-what-you-like-because-they-like-what-you-say.html

You are receiving this email because you subscribed to this feed at blogtrottr.com.

If you no longer wish to receive these emails, you can unsubscribe from this feed, or manage all your subscriptions
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 yisoajkls 的頭像
    yisoajkls

    2016徵求年菜推薦網路訂購最紅的商家.年菜訂購?台北年菜外送餐廳推薦(年菜)?年菜.今年不想做年菜推薦,網路宅配哪一家好?

    yisoajkls 發表在 痞客邦 留言(0) 人氣()