亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

返回指針值的函數

返回指針值的函數

慕村225694 2018-08-17 14:14:56
#include <stdio.h> int main(){  float score[][4]={ {60, 70, 80, 90},{56, 89, 67, 88},{34, 78, 90, 66} };    float * search ( float (* pointer)[4] ); //函數聲明    float * p;    int i,j;    for(i=0; i<3; i++) { p= search (score+i); if( p==* (score+i) ) {  printf("No:%d,score",i);  for(j=0; j<4; j++)         printf("%5.2f ",* (p+j) );  printf("\n"); } }      return 0; }    float *search ( float ( * pointer)[4]) {    float *pt; int i= 0; pt= NULL; for(; i<4; i++) if( *( *pointer+i)<60) pt = *pointer;    return(pt); } 這個程序有好多不懂  求詳解   我是初學者  求多多關照  
查看完整描述

1 回答

?
手掌心

TA貢獻1942條經驗 獲得超3個贊

float score[][4] 這是定義一個指針數組,每個元素都是一個指針,指針類型是一個int[4]的數組,叫做數組指針。score也可以理解為二維數組。

score 是一個指針,它指向數組指針數組的首地址,也就是*score = score[0]={60,70,80,90} 那么*(score+1)就是score[1]={...} ,score[0],score[1]也是一個指針,它們指向int[4]數組的地址。 所以**socre才是具體的值

float (* pointer)[4] 定義一個數組指針*pointer

search(score+i) 也就是是依次傳入score[0] score[1] score[2] 

search 函數中 *( *pointer+i)<60  :

*pointer+i 表示的是指針pointer 向后移動i位,那么*(*pointer+i)表示的是指針pointer 向后移動i位的值。所以這個表達式是在遍歷數組的值。比如傳進來的參數是score+0它是指向socre[0]的指針,那么for循環遍歷的值就是60,70,80,90 如果遇到小于60的元素就返回該指針。

 if( p==* (score+i) )    *(score+i)如前面所說是個指針,指向score[i] ,而p是search函數返回的指針,這是判斷兩個指針是否相同,是否指向同一個地址。


查看完整回答
反對 回復 2018-09-12
  • 1 回答
  • 0 關注
  • 768 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號