how i use in string varriable in switch case in c language ..... like case"vin

  1. vinay sharma  ji profile image56
    vinay sharma jiposted 7 years ago

    how i use in  string varriable in  switch case in c language .....
    like case"vinay":
    case"aman" etc

  2. Xgear profile image55
    Xgearposted 7 years ago


    Its rather simple, for example you can list various options for case together and when any of those is met it'll execute the command (case a/case A example)
    Default will work for any option not listed within switch, it isnt required though.
    If you dont end it with break; it'll automatically move on to the next case wether its met or not from the first case. (If variable is B it'll work with the statement on B and on default

    Variable may only be an integer or a string

    switch(int/char var) {
        case a:
        case A:
        case B:

    Hope this answers your question smile

  3. Booster911 profile image65
    Booster911posted 7 years ago

    This can't be done in C.

    Kernighan & Ritchie section 3.4 begins: "The switch statement is a multi-way decision which tests whether an expression matches one of a number of constant integer values, ...".

    This means that neither variables or non-integer types can be used in case statements. As strings are not integers, they can't be used in case statements.