Question:

C programming question (-:?

by  |  earlier

0 LIKES UnLike

hi! is this valid?

switch 'A': printf("something"); break;

(coz i have doubts with the 'A' part...)

thanks a lot!

 Tags:

   Report

5 ANSWERS


  1. No it should be something like

    switch(ch)

    {

       case 'A':

            printf("something");

            break;

    }

    ch is a character variable.


  2. It should be

    switch(variable)

    case 'A':

    printf("something");

    break;

  3. no

  4. No, that is not the correct usage. The correct usage would be:

    int main(){

    char smthng;

    cout << "What letter will you choose? (a-c): ";

    cin >> smthng;

    switch(smthng){

    case 'a': printf("You chose the letter A"); break;

    case 'b': printf("You chose the letter B"); break;

    case 'c': printf("You chose the letter C"); break;

    }

    }

    Always remember the very important "break;". otherwise, the switch statement will just choose the last thing in there.

  5. There is a syntax error in it for sure, and whenever u have doubt then check the program by running it, purchase C language book by Robert Lafore this is the best book on C language.

Question Stats

Latest activity: earlier.
This question has 5 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.