What is the "switch" function?

This is a discussion on What is the "switch" function? within the C Programming forums, part of the General Programming Boards category; Can someone describe to me what a "switch" does?...

  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,185
    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 12:53 AM.

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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, 02: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21