468,456 Members | 1,671 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,456 developers. It's quick & easy.

complex declarations

Hi,
recently I attended a test on C where I was asked to declare the
following declarations in one line.

void ** ( *p )(int *, char *);
int *a;

how should i do this shall i use typedef for it.

Thanks,

Jul 3 '06 #1
12 1794
no********@gmail.com wrote:
Hi,
recently I attended a test on C where I was asked to declare the
following declarations in one line.

void ** ( *p )(int *, char *);
int *a;
Why? The question doesn't make sense.

--
Ian Collins.
Jul 3 '06 #2

no********@gmail.com wrote:
Hi,
recently I attended a test on C where I was asked to declare the
following declarations in one line.

void ** ( *p )(int *, char *);
int *a;

how should i do this shall i use typedef for it.
It not clear what you were asked to do. Write out the declarations in
English or concactenate them into a single line...

Maybe you can clarify further?

Jul 3 '06 #3
for example
we can declare two variables as:
int i;
int j;

and also we can combine them to form a single line of declaration
int i,j;

in the similar way.
santosh wrote:
no********@gmail.com wrote:
Hi,
recently I attended a test on C where I was asked to declare the
following declarations in one line.

void ** ( *p )(int *, char *);
int *a;

how should i do this shall i use typedef for it.

It not clear what you were asked to do. Write out the declarations in
English or concactenate them into a single line...

Maybe you can clarify further?
Jul 3 '06 #4
it was a question.
may be they wanted to know my pointer knowledge.
Ian Collins wrote:
no********@gmail.com wrote:
Hi,
recently I attended a test on C where I was asked to declare the
following declarations in one line.

void ** ( *p )(int *, char *);
int *a;
Why? The question doesn't make sense.

--
Ian Collins.
Jul 3 '06 #5
void ** ( *p )(int *, char *); int *a;

at least, gcc allows you to do this, but it sounds to me that you have
got the question mixed up/misinterpreted. Surely no examiner would ask
such a stupid question...

Jul 3 '06 #6
void ** ( *p )(int *, char *); int *a;

at least, gcc allows you to do this, but it sounds to me that you have
got the question mixed up/misinterpreted. Surely no examiner would ask
such a stupid question...

Jul 3 '06 #7
I worked out the answer
we can write the declaration as
void **(*p)(int *,char *), *a;

now later when we use a we can typecast it to int *.
It will work without typecasting as well.
I tried it out. it works.

Thanks

no********@gmail.com wrote:
it was a question.
may be they wanted to know my pointer knowledge.
Ian Collins wrote:
no********@gmail.com wrote:
Hi,
>
>
recently I attended a test on C where I was asked to declare the
following declarations in one line.
>
void ** ( *p )(int *, char *);
int *a;
>
Why? The question doesn't make sense.

--
Ian Collins.
Jul 3 '06 #8
no********@gmail.com wrote:

Please don't top post.
santosh wrote:
>>no********@gmail.com wrote:
>>>Hi,
recently I attended a test on C where I was asked to declare the
following declarations in one line.

void ** ( *p )(int *, char *);
int *a;

how should i do this shall i use typedef for it.

It not clear what you were asked to do. Write out the declarations in
English or concactenate them into a single line...

Maybe you can clarify further?

for example
we can declare two variables as:
int i;
int j;

and also we can combine them to form a single line of declaration
int i,j;
Which many (including me) consider very bad style.

I still don't see how this relates to the question, why would you want
to put a function pointer and an int pointer declaration on one line?

--
Ian Collins.
Jul 3 '06 #9
no********@gmail.com wrote:
Hi,
recently I attended a test on C where I was asked to declare the
following declarations in one line.

void ** ( *p )(int *, char *);
int *a;

how should i do this shall i use typedef for it.
void ** ( *p )(int *, char *); int *a;

Jul 3 '06 #10
no********@gmail.com wrote:
santosh wrote:
no********@gmail.com wrote:
>
recently I attended a test on C where I was asked to declare the
following declarations in one line.
>
void ** ( *p )(int *, char *);
int *a;
>
how should i do this shall i use typedef for it.
It not clear what you were asked to do. Write out the declarations in
English or concactenate them into a single line...

Maybe you can clarify further?

for example
we can declare two variables as:
int i;
int j;

and also we can combine them to form a single line of declaration
int i,j;

in the similar way.
If what you say is correct, then it's certainly a stupid question!

Just combine them into a line like this:

void ** (*p)(int *, char *); int *a;

Jul 3 '06 #11
no********@gmail.com wrote:
recently I attended a test on C where I was asked to declare the
following declarations in one line.

void ** ( *p )(int *, char *);
int *a;

I worked out the answer
we can write the declaration as
void **(*p)(int *,char *), *a;
You changed the declaration. You were asked to declare a as pointer to
int, according to your own original post, and your solution declares it
as pointer to void.
now later when we use a we can typecast it to int *.
It will work without typecasting as well.
I tried it out. it works.
No, it doesn't. The original declaration allows you to write *a = 0;.
Your modified declaration does not. It's possible that what you wrote
is the intended solution, but if that's the case, the question was
simply plain wrong.

Jul 3 '06 #12
no********@gmail.com wrote:
I worked out the answer
we can write the declaration as
void **(*p)(int *,char *), *a;

now later when we use a we can typecast it to int *.
It will work without typecasting as well.
I tried it out. it works.
This is so gobsmackingly awful an idea that I urge you
to forget it immediately and read K&R2.

If that's what the people who were testing you /wanted/
my advice would be to run away, very fast, very far, very
soon.

--
Chris "very writhing in coils" Dollin
"Never ask that question!" Ambassador Kosh, /Babylon 5/

Jul 3 '06 #13

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Carl-Olof Almbladh | last post: by
9 posts views Thread by Christopher Benson-Manica | last post: by
reply views Thread by masood.iqbal | last post: by
14 posts views Thread by David Marsh | last post: by
2 posts views Thread by Osiris | last post: by
9 posts views Thread by void main | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by subhajit12345 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.