By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,203 Members | 1,620 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,203 IT Pros & Developers. It's quick & easy.

Declaring varibale name in paren

P: n/a
It seems that a variable can be declared with parenthesis. For example:

int main() {
int (x);
x = 5;
}

In this case it is useless. But is there any circumstances where
parenthesis are really needed ? if not why allow this ?

Thanks you in advance.
Jun 27 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Josuan wrote:
It seems that a variable can be declared with parenthesis. For example:

int main() {
int (x);
x = 5;
}

In this case it is useless. But is there any circumstances where
parenthesis are really needed ? if not why allow this ?
To declare a reference to an array, for example

int (&x)[5];

or to declare a pointer to a function

int (*ptr)(int,double);

In all cases I can think of the parentheses are there to give higher
priority to the asterisk or the ampersand that accompany the variable
name. If the parentheses were omitted, then the former case would be
come an [illegal] array of references to int and the latter would be a
declaration of a function named 'ptr' that returns a pointer to int.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.