complicated declaration

A

asit

Are the following declaration correct ??

int *p// p is a pointer to integer

int *p[]// p is an array of integer pointers

int (*p)[]// p is a pointer to an integer array

int *p()// p is a pointer to function returning
address of an integer(integer pointer)

int p(char *)//p is a function which takes a character pointer
as an argument and returns an integer

int *p(char *)// p is a function which takes a character pointer
as an argument and returns the address of an integer(integer pointer)

int (*p)(char *)// p is a pointer to a function which takes a
character pointer
as an argument and returns an integer

---------------------------------------------

int (*p(char*))[]// p is a pointer to a function and takes a character
pointer
as an argument and returns an array of integers

int p(char(*a)[])//p is a function which takes a pointer to a
character array
as an argument and returns an integer

int p(char*[])//p is a function which takes an array of character
pointers
as an argument and returns an integer

int *p(char a[])//p is a function which takes a character array
as an argument and returns an address of an integer(integer pointer)

int p(char (*a)[])//p is a function which takes a pointer to a
character array
as an argument and returns an integer

int *p(char *a[])//p is a function which takes an array of character
pointers
as an argument and returns the address of an integer(integer pointer)

int (*p)(char (*a)[])//p is a pointer to function which takes a
pointer
to a character array as an argument and returns an integer

int *(*p)(char(*a)[])//p is a pointer to function which takes a
pointer
to a character array as an argument and returns the address of an
integer(integer pointer)

--------------------------------------------

int *(*p)(char *a[])//p is a pointer to function which takes an array
of character pointers
as an argument and returns the address of an integer(integer pointer)

int (*p[])(void)//p is an array of pointers to function taking no
argument
and returning an integer

int (*p[])(char a)//p is an array of pointers to function taking a
character argument
and returning an integer

int *(*p[])(char a)//p is an array of pointers to function taking a
character argument
and returning an address of integer(integer pointer)

int *(*p[])(char *a)//p is an array of pointers to function taking a
character array as

argument and returning an address of integer(integer pointer)
 
W

WANG Cong

On Wed, 12 Mar 2008 23:54:25 -0700,asit wrote:
Are the following declaration correct ??

Yes, except the below one.

int *p()// p is a pointer to function returning address of an
integer(integer pointer)

This is wrong. p is a function instead of a function pointer.
If you want it to be a pointer, you should:

int (*p)();

And note that it can take *any* arguments, the following statements
are correct.

int (*p)();
int (*q)(int);
int (*r)(void);
p = q;
p = r;
 
J

John Bode

Are the following declaration correct ??

[snip]

int *p()// p is a pointer to function returning
address of an integer(integer pointer)

Incorrect. p is a function returning a pointer to int. What you're
thinking of is

int *(*p)();

[snip]
int (*p(char*))[]// p is a pointer to a function and takes a character
pointer
as an argument and returns an array of integers

Incorrect in that functions may not return array types (or other
function types), although you clearly understand declarator syntax.
You can return a pointer to an array:

int (*(*p(char*)))[];

p is a pointer to a function taking a char* argument and returning a
pointer to an array of int.

[snip remainder]
 
B

Ben Bacarisse

John Bode said:
Are the following declaration correct ??
int (*p(char*))[]// p is a pointer to a function and takes a character
pointer
as an argument and returns an array of integers

Incorrect in that functions may not return array types (or other
function types), although you clearly understand declarator syntax.
You can return a pointer to an array:

int (*(*p(char*)))[];

p is a pointer to a function taking a char* argument and returning a
pointer to an array of int.

ITYM int (*((*p)(char*)))[];

In general, where the name in next to a "(" it declares a function,
not a pointer to one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,689
Members
48,796
Latest member
Greg L.

Latest Threads

Top