Re: [分享] 嵌入式系統公司指標宣告考題

看板C_and_CPP作者 (非天夜翔)時間13年前 (2012/02/27 19:38), 編輯推噓6(606)
留言12則, 8人參與, 最新討論串2/5 (看更多)
※ 引述《fengchu (Galileo Galilei)》之銘言: : 美國某著名嵌入式系統公司2005年9月面試題,供板友們練習 : Write in words the data type of the identifier involved in the following : definitions. : (1) float (**def)[10]; def is a Pointer to a Pointer to an Array of 10 float def ┌─────┐0x00fffffc │0x00fffff8│ └────┼┘ └─┐ ↓ ┌─────┐0x00fffff8 │0x00fffff4│ └────┼┘ └─┐ ↓ ┌─────┐0x00fffff4 │ float01│ ├─────┤ │ float02│ ├─────┤ │ float03│ ├─────┤ │ float04│ ├─────┤ │ float05│ ├─────┤ │ float06│ ├─────┤ │ float07│ ├─────┤ │ float08│ ├─────┤ │ float09│ ├─────┤ │ float10│ └─────┘ : (2) double *(*gh)[10]; gh is a Pointer to an Array of 10 Pointer to double gh ┌─────┐0x00fffffc │0x00fffff8│ └────┼┘ └─┐ ↓ ┌─────┐0x00fffff8 │ │ ┌─────┐ │0x10000004┼─────→0x10000004│double 01 │ │ │ └─────┘ ├─────┤ │ │ ┌─────┐ │0x10000014┼─────→0x10000014│double 02 │ │ │ └─────┘ ├─────┤ │ │ ┌─────┐ │0x10000024┼─────→0x10000024│double 03 │ │ │ └─────┘ ├─────┤ │ │ ┌─────┐ │0x10000034┼─────→0x10000034│double 04 │ │ │ └─────┘ ├─────┤ │ │ ┌─────┐ │0x10000044┼─────→0x10000044│double 05 │ │ │ └─────┘ ├─────┤ │ │ ┌─────┐ │0x10000054┼─────→0x10000054│double 06 │ │ │ └─────┘ ├─────┤ │ │ ┌─────┐ │0x10000064┼─────→0x10000064│double 07 │ │ │ └─────┘ ├─────┤ │ │ ┌─────┐ │0x10000074┼─────→0x10000074│double 08 │ │ │ └─────┘ ├─────┤ │ │ ┌─────┐ │0x10000084┼─────→0x10000084│double 09 │ │ │ └─────┘ ├─────┤ │ │ ┌─────┐ │0x10000094┼─────→0x10000094│double 10 │ │ │ └─────┘ └─────┘ : (3) double (*f[10])(); f is an Array of 10 Pointer to a Function which take argument List () and return double f ┌─────┐0x00fffff8 │ │ ┌──────────┐ │0x10000004┼─────→0x10000004│double function01()│ │ └──────────┘ ├─────┤ │ │ ┌──────────┐ │0x10000004┼─────→0x10020004│double function02()│ │ └──────────┘ ├─────┤ │ │ ┌──────────┐ │0x10020004┼─────→0x10020004│double function03()│ │ └──────────┘ ├─────┤ │ │ ┌──────────┐ │0x10030004┼─────→0x10030004│double function04()│ │ └──────────┘ ├─────┤ │ │ ┌──────────┐ │0x10040004┼─────→0x10040004│double function05()│ │ └──────────┘ ├─────┤ │ │ ┌──────────┐ │0x10050004┼─────→0x10050004│double function06()│ │ └──────────┘ ├─────┤ │ │ ┌──────────┐ │0x10060004┼─────→0x10060004│double function07()│ │ └──────────┘ ├─────┤ │ │ ┌──────────┐ │0x10070004┼─────→0x10070004│double function08()│ │ └──────────┘ ├─────┤ │ │ ┌──────────┐ │0x10080004┼─────→0x10080004│double function09()│ │ └──────────┘ ├─────┤ │ │ ┌──────────┐ │0x10080004┼─────→0x10080004│double function10()│ │ └──────────┘ └─────┘ : (4) int *((*b)[10]); 我認為應該是 b is a Pointer to an Array of 10 Pointer to int ┌─────┐0x00fffffc │0x00fffff8│ └────┼┘ └─┐ ┌─────┐0x00fffff8 │ │ ┌───┐ │0x10000004┼─────→0x10000004│int 01│ │ │ └───┘ ├─────┤ │ │ ┌───┐ │0x10000014┼─────→0x10000014│int 02│ │ │ └───┘ ├─────┤ │ │ ┌───┐ │0x10000024┼─────→0x10000024│int 03│ │ │ └───┘ ├─────┤ │ │ ┌───┐ │0x10000034┼─────→0x10000034│int 04│ │ │ └───┘ ├─────┤ │ │ ┌───┐ │0x10000044┼─────→0x10000044│int 05│ │ │ └───┘ ├─────┤ │ │ ┌───┐ │0x10000054┼─────→0x10000054│int 06│ │ │ └───┘ ├─────┤ │ │ ┌───┐ │0x10000064┼─────→0x10000064│int 07│ │ │ └───┘ ├─────┤ │ │ ┌───┐ │0x10000074┼─────→0x10000074│int 08│ │ │ └───┘ ├─────┤ │ │ ┌───┐ │0x10000084┼─────→0x10000084│int 09│ │ │ └───┘ ├─────┤ │ │ ┌───┐ │0x10000094┼─────→0x10000094│int 10│ │ │ └───┘ └─────┘ 是我誤解 解答給的意思了嗎?? b is an Array of 10 Pointer to a Pointer to int b ┌─────┐0x00fffff8 │ │ ┌─────┐┌→0x11000004┌───┐ │0x10000004┼─────→0x10000004│0x11000004┼┘ │int 01│ │ │ └─────┘ └───┘ ├─────┤ │ │ ┌─────┐┌→0x13000004┌───┐ │0x10001004┼─────→0x10001004│0x12000004┼┘ │int 02│ │ │ └─────┘ └───┘ ├─────┤ │ │ ┌─────┐┌→0x13000004┌───┐ │0x10002004┼─────→0x10002004│0x13000004┼┘ │int 03│ │ │ └─────┘ └───┘ ├─────┤ │ │ ┌─────┐┌→0x14000004┌───┐ │0x10003004┼─────→0x10003004│0x14000004┼┘ │int 04│ │ │ └─────┘ └───┘ ├─────┤ │ │ ┌─────┐┌→0x15000004┌───┐ │0x10004004┼─────→0x10004004│0x15000004┼┘ │int 05│ │ │ └─────┘ └───┘ ├─────┤ │ │ ┌─────┐┌→0x16000004┌───┐ │0x10005004┼─────→0x10005004│0x16000004┼┘ │int 06│ │ │ └─────┘ └───┘ ├─────┤ │ │ ┌─────┐┌→0x17000004┌───┐ │0x10006004┼─────→0x10006004│0x17000004┼┘ │int 07│ │ │ └─────┘ └───┘ ├─────┤ │ │ ┌─────┐┌→0x18000004┌───┐ │0x10007004┼─────→0x10007004│0x18000004┼┘ │int 08│ │ │ └─────┘ └───┘ ├─────┤ │ │ ┌─────┐┌→0x19000004┌───┐ │0x10008004┼─────→0x10008004│0x19000004┼┘ │int 09│ │ │ └─────┘ └───┘ ├─────┤ │ │ ┌─────┐┌→0x1a000004┌───┐ │0x10009004┼─────→0x10009004│0x1a000004┼┘ │int 10│ │ │ └─────┘ └───┘ └─────┘ : (5) long (*fun)(int) fun is a Pointer to a Function which take argument List (int) and return long fun ┌─────┐0x00fffffc │0xa0fffff8│ └────┼┘ └───┐ ↓ ┌───────┐0xa0fffff8 │long func(int)│ └───────┘ : (6) int (*(*F)(int, int))(int); F is a Pointer to a Function which take argument List (int, int) and return a Pointer to a Function which take argument List (int) and return int F ┌─────┐0x00fffffc │0xa0fffff8│ └────┼┘ └───┐ ↓ 0xa0fffff8 ┌───────────┐ │funcPTR func1(int,int)│ └─┼─────────┘ └─────┐ funcPTR┌─────┐0xb0fffffc │0xa1fffff8│ └────┼┘ └─┐ ↓ 0xa1fffff8 ┌───────┐ │int func2(int)│ └───────┘ : 解答在次頁 : (1) def是一個指向指標的指標,*def是指向一個有10個元素的一維陣列的指標,陣列的 : 元素型別為float : (2) gh是一個指標,指向一個有10個元素的一維陣列,陣列元素型別為double* : (3) f是一個有10個元素的陣列,陣列的元素型別為函式指標,指向的函式為沒有參數且 : 返回值型別為double的函式 : (4) b是一維陣列的指標,陣列元素型別為int* : (5) fun是一個函數指標。指向的函數輸入參數型別為int,回傳值型別為long : (6) F是一個函數指標,指向的函式輸入參數為(int, int),並返回一個函式指標。返回 : 的函式指標指向一個輸入參數為(int)回傳值型別為int的函式 -- 渴望飛翔在自由中, 期望逃離這拘束的現實, 一切都讓他隨著而去, 獨自躲在黑暗空氣中, 舔舐被狠狠撕裂的傷口。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 1.163.153.167 ※ 編輯: csihcs 來自: 1.163.153.167 (02/28 03:41) ※ 編輯: csihcs 來自: 1.163.153.167 (02/28 03:48) ※ 編輯: csihcs 來自: 1.163.153.167 (02/28 04:11) ※ 編輯: csihcs 來自: 1.163.153.167 (02/28 04:30) ※ 編輯: csihcs 來自: 1.163.153.167 (02/28 04:36)

02/28 05:11, , 1F
先推精巧的圖示:) 另外第四題我和csihcs大的理解相同
02/28 05:11, 1F

02/28 09:48, , 2F
先推了
02/28 09:48, 2F
※ 編輯: csihcs 來自: 1.163.141.68 (02/28 12:00)

02/28 13:14, , 3F
02/28 13:14, 3F

02/28 16:01, , 4F
推 精巧的圖示
02/28 16:01, 4F

02/28 16:21, , 5F
原文第四題解答是錯的 b 是 poinnter 沒錯
02/28 16:21, 5F

02/28 16:24, , 6F
樓上大概誤解了 原文中寫b是一個一維陣列的指標 代表他是
02/28 16:24, 6F

02/28 16:25, , 7F
一個指標,指向的型態是一維陣列...就像是fun是個函數指標
02/28 16:25, 7F

02/28 16:26, , 8F
代表他是個指標,指向的型態是個函數...
02/28 16:26, 8F

02/28 16:27, , 9F
話說之前好像有看到過C declaration translator XD
02/28 16:27, 9F

02/28 17:12, , 10F
http://www.cdecl.org/ <-- 用樓上的keyword
02/28 17:12, 10F

02/28 17:47, , 11F
所以考這種題目有夠無聊~
02/28 17:47, 11F

03/04 01:55, , 12F
先推!
03/04 01:55, 12F
文章代碼(AID): #1FIzkddM (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1FIzkddM (C_and_CPP)