Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 21-07-2008, 04:51 PM   #1 (permalink)
Right Off the Assembly Line
 
Join Date: Jun 2008
Posts: 2
Question switch case in C


hi every1..
how to implement constant expressions using switch statements in C?like we implement expressions using if statement

if(a<b+c) or if((a<b)&&(b<c))........

how can we do it using switch case(rather than implementing constant or character values)?
thinkingon is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 21-07-2008, 06:08 PM   #2 (permalink)
paralinux
 
Join Date: Jul 2008
Location: Noida
Posts: 86
Thumbs down Re: switch case in C

Hello
This may disappoint u but switch case construct is not available in C(as per my knowledge). Its there in C++(I dont know much about C but am comfortable with C++). And in C++ switch case construct is used for constant conditions, it not used for the kind of statements u wish to use it for( oops another disappointment!!!). I hope u know the syntax of the switch case construct.

It accepts a value in the parenthesis of switch and executes the statements under the corresponding case label. If it does not find any then it executes the default statement.
anuvrat_parashar is offline  
Old 21-07-2008, 07:01 PM   #3 (permalink)
OSS Enthusiast!
 
nitish_mythology's Avatar
 
Join Date: Sep 2005
Location: Hills of Kumaoun
Posts: 664
Default Re: switch case in C

Switch cannot deal with ranges of value AFAIK. Only with (==) operator.
__________________
Do you know, Shinigamis only eat apples???
nitish_mythology is offline  
Old 21-07-2008, 09:23 PM   #4 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: switch case in C

Use a simple else-if ladder for expression-like conditions. Switch is made for jumping based on a value, else-if is more logical than switch here.
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 22-07-2008, 11:18 AM   #5 (permalink)
Broken In
 
Join Date: Sep 2004
Location: Queen of the hills:Shimla
Posts: 160
Default Re: switch case in C

Switch can be used only all the possible outcomes of the query are known and the value under comparison cannot be an expression but a constant.

And switch is there in the C library and can be used freely if you know what to do with it.
anshul is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
KVM Switch... shivg33k Hardware Q&A 1 03-07-2008 02:32 AM
My first Case Mod Artemis Hardware Q&A 45 14-06-2008 05:54 PM
All About Case Fan Revolution Hardware Q&A 1 08-04-2008 09:02 AM
Switch or HUB? linardni QnA (read only) 7 22-08-2005 03:04 PM
should we get a dvd case anirudh QnA (read only) 9 29-10-2004 05:11 PM

 
Latest Threads
- by Sujeet
- by clmlbx
- by Sujeet
- by icebags

Advertisement




All times are GMT +5.5. The time now is 11:06 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2