switch statement



 DEVELOP > c-Plus-Plus > switch statement

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "D"
Date: 01 Dec 2004 01:09:16 PM
Object: switch statement
Can a switch statement have an arithmetic attribute in it. For example
switch (x / 10)
{
case a: place your statements here
}
Thanks
.

User: "Rob Williscroft"

Title: Re: switch statement 01 Dec 2004 01:27:13 PM
D wrote in news:d7d85b9a.0412011109.c229735@posting.google.com in
comp.lang.c++:

Can a switch statement have an arithmetic attribute in it. For example
switch (x / 10)
{
case a: place your statements here
}


No idea what you mean by "arithmetic attribute in it", if you mean
a non-compiletime-constant, then no.
int const ten = 10;
int main()
{
int x = 100, a = 10;
switch ( x / 10 )
{
case a: // illegal must be a compile time constant
case 10: // ok
case ten; // also ok.
}
}
HTH.
Rob.
--
http://www.victim-prime.dsl.pipex.com/
.
User: "Default User"

Title: Re: switch statement 01 Dec 2004 04:20:28 PM
Rob Williscroft wrote:

D wrote in news:d7d85b9a.0412011109.c229735@posting.google.com in
comp.lang.c++:

Can a switch statement have an arithmetic attribute in it. For
example switch (x / 10)
{
case a: place your statements here
}



No idea what you mean by "arithmetic attribute in it", if you mean
a non-compiletime-constant, then no.

Ah, you read it as asking about the case labels. I confess that now I'm
not clear what was meant. I took it to mean the controlling expression.
You're right, of course, about case labels.
Brian
.


User: "Default User"

Title: Re: switch statement 01 Dec 2004 04:17:02 PM
D wrote:

Can a switch statement have an arithmetic attribute in it. For
example switch (x / 10)
{
case a: place your statements here
}

You mean expression, not attribute. The answer is yes, as long as the
expression yields an integer type. Assuming x is an integer type, then
your example above will have integer division and all will be well.
Brian
.

User: "Victor Bazarov"

Title: Re: switch statement 01 Dec 2004 01:28:03 PM
D wrote:

Can a switch statement have an arithmetic attribute in it. For example
switch (x / 10)
{
case a: place your statements here
}

Yes.
V
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER