Computer Science, asked by sreeja3, 1 year ago

write about the switch statement and write the syntax.

Answers

Answered by Anonymous
5
switch case statement is used for going according to the users choice. .
Syntax:
switch(choice)
{
case 1: ;
break;
case 2: ;
break ;
default : ;
}
Answered by SurajSaraf
1
Switch statement is a function that we use to choose particular data from the program. We use it as like another form of 'if','else' statement. 

syntax
i am writing a simple program of c language.(about the name)
...................................\*header file include*\ 
...............................\*header file include*\
.....................................\*main function*\
{
char name;
printf("\n enter person name to get his roll number\n");
scanf("%s",&name);
switch(name)
{
case 'AKASH':
printf("\n Roll no of Akash is%d"5);
break;
case 'AMAR':
printf("\n Roll no of Amar is %d",2);
break;
default:
printf("\n NO person is available in this name");
}
 return 0;
getch();
}

Here when you type any name in capital letter it will be assume in the part of RAM that we call 'name' or provide a name.

name will  be checked by switch case.

If it match with any case then your compiler run the part of the case and when it come an watch break statement then compiler will come in 'return 0;'
statement.

IF name dose not match with any case then compiler come into the default statement. 

BREAK statement help to the compiler to exit the switch case .
Without break statement compiler will come into next case and it will complete every case.

If you don't understand that then you can sms me personally. I will try to better understand to you.
 
Similar questions