2

I know that int* foo(int) prototype means that foo is a function that takes an integer argument and returns a pointer to an integer.But what does the following mean?

  const int* foo(int);

I tried to reason but failed.My book doesn't say anything about this but I see stuff like this in library function prototypes.So please tell me what it means.

Thokchom
  • 1,602
  • 3
  • 17
  • 32

3 Answers3

1

So that value pointed by returned address can't be change via address (useful when foo() returns address of const).

const int* p2c =  foo(int);
*p2c=10;  <-- "error"
Grijesh Chauhan
  • 57,103
  • 20
  • 141
  • 208
1

from cdecl:

this means

declare foo as function (int) returning pointer to const int

MOHAMED
  • 41,599
  • 58
  • 163
  • 268
1
const int* foo(int);

foo is a function that takes an integer argument and returns a pointer to an const integer.It means you are allowed to change pointer but not it's value.

Dayal rai
  • 6,548
  • 22
  • 29