Thread: Switch statement / default:

  1. #1
    Registered User
    Join Date
    Jan 2007
    Location
    Euless, TX
    Posts
    144

    Switch statement / default:

    I know that the "default:" is optional in a switch statement, and if not a part of the switch statement and no values match any case statements, there would be no action. If, however, a default is included and there is no action to take under the default, and a value that had no case statement for that value, and was therefore passed down to the default, could there be any action that may cause faults to the program being executed?

    Thanks.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What do you mean by "cause faults to the program being executed"?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jan 2007
    Location
    Euless, TX
    Posts
    144
    Could there be a possibility of the program crashing, for example?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    No, except due to some other problem.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Jan 2007
    Location
    Euless, TX
    Posts
    144
    I didn't think so, but wanted another opinion of a real expert.

    Thanks LL

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stack operations from switch statement elements
    By mlsrar in forum C Programming
    Replies: 15
    Last Post: 10-02-2008, 01:12 PM
  2. switch statement
    By guillermoh in forum C Programming
    Replies: 5
    Last Post: 03-10-2008, 02:17 PM
  3. Switch statement problem
    By jalex39 in forum C Programming
    Replies: 6
    Last Post: 03-08-2008, 04:05 PM
  4. Switch Statement
    By DarkDot in forum C++ Programming
    Replies: 11
    Last Post: 03-28-2007, 10:11 PM
  5. Efficiency with the switch() statement...
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 10-14-2001, 02:47 PM