Thread: What is the "switch" function?

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    15

    What is the "switch" function?

    Can someone describe to me what a "switch" does?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Switch isn't a function, it's a keyword.

    I'm sure someone here could describe to you what a "switch" does, but we are forced to wonder why you didn't type "C switch" into Google and hit "I'm feeling lucky". (I know some people don't like MSDN help docs, but this one doesn't look too bad.)

  3. #3
    Registered User
    Join Date
    Feb 2008
    Location
    PUNE
    Posts
    23
    switch statement provides multiple way branching. ie it allows users to select any 1 of the several alternatives.

    its syntax is:
    Code:
      switch (expression)
       
        {
       
        case label 1 : block1;
                             break;
      
        case label 2 : block2;
                            break;
     
        case label 3 : block3;
                            break;
                          .
                          .
                          .
                          .
                          .
                          
     case labelmax : blockmax;
                                 break;
     
                default :   dblock;
                                 break;
                     }
    Last edited by ajayd; 02-15-2008 at 01:53 AM.

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM