
- Pascal 教程
- Pascal - 主頁
- Pascal - 概覽
- Pascal - 環境設定
- Pascal - 程式結構
- Pascal - 基本語法
- Pascal - 資料型別
- Pascal - 變數型別
- Pascal - 常量
- Pascal - 運算子
- Pascal - 決策制定
- Pascal - 迴圈
- Pascal - 函式
- Pascal - 過程
- Pascal - 變數範圍
- Pascal - 字串
- Pascal - 布林值
- Pascal - 陣列
- Pascal - 指標
- Pascal - 記錄
- Pascal - 變體
- Pascal - 集合
- Pascal - 檔案處理
- Pascal - 記憶體
- Pascal - 單元
- Pascal - 日期和時間
- Pascal - 物件
- Pascal - 類
- Pascal 有用資源
- Pascal - 快速指南
- Pascal - 有用資源
- Pascal - 討論
Pascal - 將指標傳遞給子程式
指標變數可以在函式和過程引數中作為引數傳遞。指標變數既可以作為值引數,也可以作為變數引數傳遞;但是,當作為變數引數傳遞時,子程式可能會無意中更改指標的值,這將導致奇怪的結果。
以下程式說明如何將指標傳遞給函式 −
program exPointertoFunctions; type iptr = ^integer; var i: integer; ptr: iptr; function getNumber(p: iptr): integer; var num: integer; begin num:=100; p:= @num; getNumber:=p^; end; begin i := getNumber(ptr); writeln(' Here the pointer brings the value ', i); end.
編譯並執行以上程式碼後,將產生如下結果 −
Here the pointer brings the value: 100
pascal_pointers.htm
廣告