-4

I want to know what is the meaning of the following statements.

int *abc(int,int);
int (*abc)(int,int);

and how these pointers are different from the ordinary pointer. ex:

int *ptr;

Thank you

JJJ
  • 32,902
  • 20
  • 89
  • 102

2 Answers2

1

Can a pointer take arguments?

No, a pointer is just a variable which stores address of a memory location.

int *abc(int,int);

This is a declaration of function abc which takes two arguments, both of type int, and returns a pointer to an int type.

int (*abc)(int,int);

Here, abc is a pointer that can point to a function which takes two int type arguments and returns an int.
Say, if you have a function fun:

int fun(int a, int b) {
    return a + b;
}

abc can point to fun(), like this:

abc = fun;

then you can call function fun using abc pointer, like this:

abc(4, 5);

how these pointers are different from the ordinary pointer. ex:
int *ptr;

Here, ptr is a pointer which can store the address of an int type.

Hence, all the pointers store some memory location, the difference lies in the address of a type they point to.

H.S.
  • 11,654
  • 2
  • 15
  • 32
0

assuming C/C++
this: int *abc(int,int); is a prototype of function returning a pointer to int and taking two arguments of type int

this: int (*abc)(int,int); is a declaration of a pointer to function returning int and taking two arguments of type int

mangusta
  • 3,470
  • 5
  • 24
  • 47