473,395 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 2056
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Alan Holloway | last post by:
Hi all, Firstly thanks for your golden insight on my earlier post re bitwise operations. I now have another question! I've just been reading the excellent Peter van der Linden excerpt ...
4
by: Carl-Olof Almbladh | last post by:
Dear all, In C99, complex is now built in, and the C library contains functions for complex exp, etc. It is not so easy to find info about the syntax if one is not willing to buy the ISO/ANSI...
9
by: Christopher Benson-Manica | last post by:
Recently, the following definition was posted to comp.lang.c++: > char **Arr; 1) Is the type of this object "array of 3 (array of two of pointer to pointer to char)"? If not, what is it? ...
0
by: masood.iqbal | last post by:
I have always had trouble correctly interpreting complex type declarations without using the "declarator parser" program given in K&R. Then someone taught me about the "Clockwise" Rule. Start with...
14
by: David Marsh | last post by:
Can someone show me or point me to an example of declaring and initializing complex numbers in C99? Also, in looking at complex.h, I don't see any library calls for + - * or /. How are the basic...
11
by: nospam | last post by:
Is there a utility that takes an arbitrarily complex C language declaration, checks it validity, and breaks it down into something more understandable. Is there a executable version for wintel...
2
by: Osiris | last post by:
Is there a program that can explain complex C declarations like char (*(*x)( )) like so: x is array of pointers to functiion returning pointer to array of char ???
9
by: void main | last post by:
I'm rather new to complex numbers in C and was wondering, how do I initialize a complex variable properly if the imaginary part is 0. I tried -------- #include <complex.h> float complex c...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.