Re: [問題] 有關pointer
※ 引述《u8906250.bbs@ptt.cc (陷入貓的國度 就當隻貓吧)》之銘言:
> 我都是用struct取代二維陣列
> 像是 struct row { int item[10]; }
> 再宣告struct陣列 struct row grids[10];
> 這樣在傳參數時就很方便...
是很方便沒錯,
但是就是用起來會比較累一點,
另外,
其實實際的應用程式裡,
很少會有機會在 function 內部需要定義固定大小的 2d array,
又還要整個 array pass 出去的,
通常固定大小的 2d array 會是 global variable,
而 function 內部的大都是 (int **) 之類,
被動態配置出來的 2d array,
所以在正式由純 C 撰寫的應用程式裡面,
參數都是 pointer 而不是 array,
而 C++ 則是有規定不能以 by value 丟 array,
所以才會想說包成 struct 看看,
但這不單純是規定和好不好用的問題,
by value 傳遞大東西本身會讓程式比較慢是一大主因。
--
Name: Tseng, Ling-hua E-mail Address: uranus@it.muds.net
School: National Tsing Hua University Department: Computer Science
Interesting: C++, Compiler, PL/PD, OS, VM, Large-scale software design
Researching: Undecided
Homepage: https://it.muds.net/~uranus
--
╔═══╗ ┼────────────────────────╮
║狂狷 ║ │* Origin:[ 狂 狷 年 少 ] whshs.cs.nccu.edu.tw ╰─╮
║ 年少║ ┼╮ < IP:140.119.164.252 > ╰─╮
╚╦═╦╝ ╰ * From:61-230-217-167.dynamic.hinet.net
─╨─╨─ KGBBS ─ ◎ 遨翔"BBS"的狂狷不馴;屬於年少的輕狂色彩 ◎
推
11/02 13:06, , 1F
11/02 13:06, 1F
→
11/02 13:07, , 2F
11/02 13:07, 2F
討論串 (同標題文章)
完整討論串 (本文為第 4 之 4 篇):
0
1
Programming 近期熱門文章
PTT數位生活區 即時熱門文章