The difference between int *p () and int (*p) ()

Source: Internet
Author: User

int *p () is a function that returns a pointer

Int (*p) () is a pointer to a function

function that returns the pointer:

int * A (int x,int y);

There are a number of students (each student has 4 courses), requiring the user to enter the student serial number, can output the student's full results. Implemented with pointer functions.

#include

void main()

{float *score[ ] [4]={{60,

                     {56 , Span style= "font-family: ' Times New Roman ';" >89 , 67 , 88} , {34 , 78 , , 66}};

float ? *search(float (*pointer)[4],int n);

float? *p;

int i,m;

printf(″Enterthe number of student: ″);

scanf(″%D″,&M);

printf(″ thescores of No. %d is:\n″,m);

p=Search(score,m);

 for (i=0;i<4;i++ )

 printf(″%5. 2f\t″,*(p+i));

Float * Search (float (*pointer) [4 ],int N)

{ float *pt;

pt=*(pointer+n);/ /(equivalent to *(* (p+n) +0))=* (* (p+n) )

return (PT);

}

For the students in the example above, find out which students have failed courses and their student numbers.

#include

void main()

{float *score [  ][4 ] ={{60 , 70 , 80 , , style= "font-family: ' Times New Roman ';" >{56 ,

---------------------;

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 scores: ″,i);

for (j=0;j<4;j++) 

  printf(″%5.2F″,*(p+j));

printf(″\n″);} 

   }

}

Pointers to functions

argument function name F1 f2 

  ↓ ↓  

void Sub (int (*x1) (int) ,Int (*x2) (int,int) )

{ int a,b,i,j;

a=(*x1)(i); /* call F1 function */

b=(*x2)(i,j);/* call f2 function */

...

}

Example: Set up a function processthat implements different functions each time it is called. Enter A and b two numbers, first call the process to find A and B in the large, the second to find the small one, the third to seek the sum of A and B.

#include

void main()

{ int max(int,int); /* function Declaration * /

int min(int,int); /* function Declaration * /

int add(int,int);/ * function Declaration * /

void process (int, int, int (*fun) (); /* function Declaration * /

  int A, b;

 printf(″Enter a and b: ″);

 scanf(″%D,%D″,&A,&B);

printf(″max=″);

Process (A,b,max);

 printf(″min=″);

 process(a,b,min);

 printf(″sum=″);

 process(A,b,add);

......

int Add (int x,int y) / * function definition * /

{ intz;

z=x+y;

return(z);

void process (int x,int y,Int (*fun) (int,int))

{ int result;

result = (*fun) (x, y);

printf(″%d\n″, result);

The difference between int *p () and int (*p) ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.