1.返回指针值的函数

一个函数可以带回一个整型值、字符值、实型值等,也可以带回指针型的数据,即地址。其概念与以前类似,只是带回的值的类型是指针类型而已。

这种带回指针值的函数,一般定义形式为
    
    类型名  *函数名(参数表列);

例如:
   int *a(int x,int y);

例题:有若干个学生的成绩(每个学生有4门课程),要求在用户输入学生序号以后,能输出该学生的全部成绩。用指针函数来实现。

#include <stdio.h>

void main()
{
      double score[][4] = {{60.0, 70.0, 80.5, 90.5}, {56.0, 89.0, 67.0, 88.0}, {34.2, 78.5, 90.5, 66.0}};
      double *search(double(*pointer)[4], int n);
      double *p;
      int i, m;

      printf("Please enter the number of student: ");
      scanf("%d", &m);

      printf("The scores of No.%d are: \n", m);

      p = search(score, m);

      for( i=0; i < 4; i++)
      {
            printf("%5.2f\t", *(p + i));
      }

      printf("\n\n\n");
}

double *search(double (*pointer)[4], int n)
{
      double *pt;

      pt = *(pointer + n);

      return pt;
}
View Code

相关文章:

  • 2022-12-23
  • 2021-06-03
  • 2021-12-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-01
猜你喜欢
  • 2021-12-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
  • 2022-12-23
相关资源
相似解决方案