SlideShare una empresa de Scribd logo
1 de 21
*
1. What is the output?
main()
{
int i=3;
switch(i)
{
default:printf("zero");
case 1: printf("one");
break;
case 2:printf("two");
break;
case 3: printf("three");
break;
}
}
Answer :
three
Explanation :
The default case can be placed anywhere inside the loop. It is
executed only when all other cases doesn't match.
2.#include<stdio.h>
main()
{
int i=1,j=2;
switch(i)
{
case 1: printf("GOOD");
break;
case j: printf("BAD");
break;
}
}
Answer:
Compiler Error: Constant expression required in function main.
Explanation:
The case statement can have only constant expressions (this
implies that we cannot use variable names directly so an error).
3.main()
{
float i=1.5;
switch(i)
{
case 1: printf("1");
case 2: printf("2");
default : printf("0");
}
}
Answer:
Compiler Error: switch expression not integral
Explanation:
Switch statements can be applied only to
integral types.
4. #include<stdio.h>
int main()
{
int i = 1;
switch(i)
{
case 1:
printf("Case1");
break;
case 1*2+4:
printf("Case2");
break;
}
return 0;
}
A. Error: in case 1*2+4 statement
B. Error: No default specified
C. Error: in switch statement
D. No Error
Answer: Option D
Explanation:
Constant expression are accepted in switch
It prints "Case1"
5. #include<stdio.h>
int main()
{
int i=1;
for(;;)
{
printf("%dn", i++);
if(i>10)
break;
}
return 0;
}
A. There should be a condition in the for loop
B. The two semicolons should be dropped
C. The for loop should be replaced with while loop.
D. No error
Answer: Option D
6. #include<stdio.h>
int main()
{
int a = 10;
switch(a)
{
}
printf("This is c program.");
return 0;
}
A. Error: No case statement specified
B. Error: No default specified
C. No Error
D. Error: infinite loop occurs
Answer: Option C
7. #include<stdio.h>
int main()
{
int i = 1;
switch(i)
{
printf("This is c program.");
case 1:
printf("Case1");
break;
case 2:
printf("Case2");
break;
}
return 0;
}
A. Error: No default specified
B. Error: Invalid printf statement after switch statement
C. No Error and prints "Case1"
D. None of above
Answer: Option C
8. #include<stdio.h>
int main()
{
int a = 5;
switch(a)
{
case 1:
printf("First");
case 2:
printf("Second");
case 3 + 2:
printf("Third");
case 5:
printf("Final");
break;
}
return 0;
}
A. There is no break statement in each case.
B. Expression as in case 3 + 2 is not allowed.
C. Duplicate case case 5:
D. No error will be reported.
Answer: Option C
9. include <stdio.h>
int main()
{
int i=0;
for(i=0; i<20; i++)
{
switch(i)
{
case 0:
i+=5;
case 1:
i+=2;
case 5:
i+=5;
}
default:
i+=4;
break;
}
printf("%d ", i);
}
getchar();
return 0;
OUTPUT: 21
10. #include<stdio.h>
int main()
{
int i=3;
switch(i)
{
case 1:
printf("Hellon");
case 2:
printf("Hin");
case 3:
continue;
default:
printf("Byen");
}
return 0;
}
OUTPUT: Misplaced Continue
11. #include<stdio.h>
int main()
{
int i=4;
switch(i)
{
default:
printf("This is
defaultn");
case 1:
printf("This is case
1n");
break;
case 2:
printf("This is case
2n");
break;
case 3:
printf("This is case 3n");
}
return 0;
}
Output:
This is default
This is case1
12. main()
{
float me = 1.1;
double you = 1.1;
if(me==you)
printf("I love SWEETS");
else
printf("I hate MEDICINES");
}
Answer:
I hate MEDICINES

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

CONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGECONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGE
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
 
Control structures in c
Control structures in cControl structures in c
Control structures in c
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c language
 
C if else
C if elseC if else
C if else
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
 
Structure in programming in c or c++ or c# or java
Structure in programming  in c or c++ or c# or javaStructure in programming  in c or c++ or c# or java
Structure in programming in c or c++ or c# or java
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
Control statements
Control statementsControl statements
Control statements
 
7 decision-control
7 decision-control7 decision-control
7 decision-control
 
Control structure
Control structureControl structure
Control structure
 
Conditionalstatement
ConditionalstatementConditionalstatement
Conditionalstatement
 
Flow of control ppt
Flow of control pptFlow of control ppt
Flow of control ppt
 
C++ STATEMENTS
C++ STATEMENTS C++ STATEMENTS
C++ STATEMENTS
 
If statements in c programming
If statements in c programmingIf statements in c programming
If statements in c programming
 
Control structure in c
Control structure in cControl structure in c
Control structure in c
 
Control and conditional statements
Control and conditional statementsControl and conditional statements
Control and conditional statements
 
basic of desicion control statement in python
basic of  desicion control statement in pythonbasic of  desicion control statement in python
basic of desicion control statement in python
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
 

Destacado

Routing Protocols and Concepts - Chapter 1
Routing Protocols and Concepts - Chapter 1Routing Protocols and Concepts - Chapter 1
Routing Protocols and Concepts - Chapter 1
CAVC
 
Power electronic drives ppt
Power electronic drives pptPower electronic drives ppt
Power electronic drives ppt
Sai Manoj
 

Destacado (13)

Inheritance
Inheritance Inheritance
Inheritance
 
Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statement
 
Advanced Introduction to Java Multi-Threading - Full (chok)
Advanced Introduction to Java Multi-Threading - Full (chok)Advanced Introduction to Java Multi-Threading - Full (chok)
Advanced Introduction to Java Multi-Threading - Full (chok)
 
Working of Shaping machine and Drilling machine
Working of Shaping machine and Drilling machineWorking of Shaping machine and Drilling machine
Working of Shaping machine and Drilling machine
 
Switch: How to Change Things When Change is Hard
Switch:  How to Change Things When Change is HardSwitch:  How to Change Things When Change is Hard
Switch: How to Change Things When Change is Hard
 
Routing Protocols and Concepts - Chapter 1
Routing Protocols and Concepts - Chapter 1Routing Protocols and Concepts - Chapter 1
Routing Protocols and Concepts - Chapter 1
 
Oprerator overloading
Oprerator overloadingOprerator overloading
Oprerator overloading
 
Power electronic drives ppt
Power electronic drives pptPower electronic drives ppt
Power electronic drives ppt
 
difference between hub, bridge, switch and router
difference between hub, bridge, switch and routerdifference between hub, bridge, switch and router
difference between hub, bridge, switch and router
 
Ppt of routing protocols
Ppt of routing protocolsPpt of routing protocols
Ppt of routing protocols
 
Plastics .ppt
Plastics .pptPlastics .ppt
Plastics .ppt
 
Katalog Wiosna Lato 2017 - Conhpol Elite
Katalog Wiosna Lato 2017 - Conhpol EliteKatalog Wiosna Lato 2017 - Conhpol Elite
Katalog Wiosna Lato 2017 - Conhpol Elite
 
Redesssss
RedesssssRedesssss
Redesssss
 

Similar a Switch statement mcq

C interview question answer 2
C interview question answer 2C interview question answer 2
C interview question answer 2
Amit Kapoor
 
c interview progs.pdf
c interview progs.pdfc interview progs.pdf
c interview progs.pdf
pooja82042
 
C aptitude.2doc
C aptitude.2docC aptitude.2doc
C aptitude.2doc
Srikanth
 
C aptitude scribd
C aptitude scribdC aptitude scribd
C aptitude scribd
Amit Kapoor
 

Similar a Switch statement mcq (20)

Aptitute question papers in c
Aptitute question papers in cAptitute question papers in c
Aptitute question papers in c
 
Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02
 
C interview question answer 2
C interview question answer 2C interview question answer 2
C interview question answer 2
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
c interview progs.pdf
c interview progs.pdfc interview progs.pdf
c interview progs.pdf
 
Technical aptitude Test 1 CSE
Technical aptitude Test 1 CSETechnical aptitude Test 1 CSE
Technical aptitude Test 1 CSE
 
Learning C programming - from lynxbee.com
Learning C programming - from lynxbee.comLearning C programming - from lynxbee.com
Learning C programming - from lynxbee.com
 
CH-4 (1).pptx
CH-4 (1).pptxCH-4 (1).pptx
CH-4 (1).pptx
 
Decision Making and Looping
Decision Making and LoopingDecision Making and Looping
Decision Making and Looping
 
while loop in C.pptx
while loop in C.pptxwhile loop in C.pptx
while loop in C.pptx
 
C aptitude.2doc
C aptitude.2docC aptitude.2doc
C aptitude.2doc
 
Captitude 2doc-100627004318-phpapp01
Captitude 2doc-100627004318-phpapp01Captitude 2doc-100627004318-phpapp01
Captitude 2doc-100627004318-phpapp01
 
C operators
C operatorsC operators
C operators
 
Programming basics
Programming basicsProgramming basics
Programming basics
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
C aptitude scribd
C aptitude scribdC aptitude scribd
C aptitude scribd
 
Lec 10
Lec 10Lec 10
Lec 10
 
What is c
What is cWhat is c
What is c
 
Very interesting C programming Technical Questions
Very interesting C programming Technical Questions Very interesting C programming Technical Questions
Very interesting C programming Technical Questions
 
Decision statements in c laguage
Decision statements in c laguageDecision statements in c laguage
Decision statements in c laguage
 

Más de Parthipan Parthi

Más de Parthipan Parthi (20)

802.11 mac
802.11 mac802.11 mac
802.11 mac
 
Ieee 802.11 wireless lan
Ieee 802.11 wireless lanIeee 802.11 wireless lan
Ieee 802.11 wireless lan
 
Computer network
Computer networkComputer network
Computer network
 
Ieee 802.11 wireless lan
Ieee 802.11 wireless lanIeee 802.11 wireless lan
Ieee 802.11 wireless lan
 
Session 6
Session 6Session 6
Session 6
 
Queuing analysis
Queuing analysisQueuing analysis
Queuing analysis
 
WAP
WAPWAP
WAP
 
Alternative metrics
Alternative metricsAlternative metrics
Alternative metrics
 
Ethernet
EthernetEthernet
Ethernet
 
Ieee 802.11 wireless lan
Ieee 802.11 wireless lanIeee 802.11 wireless lan
Ieee 802.11 wireless lan
 
Data structures1
Data structures1Data structures1
Data structures1
 
Data structures 4
Data structures 4Data structures 4
Data structures 4
 
Data structures2
Data structures2Data structures2
Data structures2
 
Data structures 3
Data structures 3Data structures 3
Data structures 3
 
Input output streams
Input output streamsInput output streams
Input output streams
 
Io stream
Io streamIo stream
Io stream
 
Dbms lab questions
Dbms lab questionsDbms lab questions
Dbms lab questions
 
REVERSIBLE DATA HIDING WITH GOOD PAYLOAD DISTORTIONPpt 3
REVERSIBLE DATA HIDING WITH GOOD PAYLOAD DISTORTIONPpt 3 REVERSIBLE DATA HIDING WITH GOOD PAYLOAD DISTORTIONPpt 3
REVERSIBLE DATA HIDING WITH GOOD PAYLOAD DISTORTIONPpt 3
 
New syllabus combined_civil_services
New syllabus combined_civil_servicesNew syllabus combined_civil_services
New syllabus combined_civil_services
 
Pspice
PspicePspice
Pspice
 

Último

Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Último (20)

Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 

Switch statement mcq

  • 1. *
  • 2. 1. What is the output? main() { int i=3; switch(i) { default:printf("zero"); case 1: printf("one"); break; case 2:printf("two"); break; case 3: printf("three"); break; } }
  • 3. Answer : three Explanation : The default case can be placed anywhere inside the loop. It is executed only when all other cases doesn't match.
  • 4. 2.#include<stdio.h> main() { int i=1,j=2; switch(i) { case 1: printf("GOOD"); break; case j: printf("BAD"); break; } }
  • 5. Answer: Compiler Error: Constant expression required in function main. Explanation: The case statement can have only constant expressions (this implies that we cannot use variable names directly so an error).
  • 6. 3.main() { float i=1.5; switch(i) { case 1: printf("1"); case 2: printf("2"); default : printf("0"); } }
  • 7. Answer: Compiler Error: switch expression not integral Explanation: Switch statements can be applied only to integral types.
  • 8. 4. #include<stdio.h> int main() { int i = 1; switch(i) { case 1: printf("Case1"); break; case 1*2+4: printf("Case2"); break; } return 0; }
  • 9. A. Error: in case 1*2+4 statement B. Error: No default specified C. Error: in switch statement D. No Error Answer: Option D Explanation: Constant expression are accepted in switch It prints "Case1"
  • 10. 5. #include<stdio.h> int main() { int i=1; for(;;) { printf("%dn", i++); if(i>10) break; } return 0; }
  • 11. A. There should be a condition in the for loop B. The two semicolons should be dropped C. The for loop should be replaced with while loop. D. No error Answer: Option D
  • 12. 6. #include<stdio.h> int main() { int a = 10; switch(a) { } printf("This is c program."); return 0; }
  • 13. A. Error: No case statement specified B. Error: No default specified C. No Error D. Error: infinite loop occurs Answer: Option C
  • 14. 7. #include<stdio.h> int main() { int i = 1; switch(i) { printf("This is c program."); case 1: printf("Case1"); break; case 2: printf("Case2"); break; } return 0; }
  • 15. A. Error: No default specified B. Error: Invalid printf statement after switch statement C. No Error and prints "Case1" D. None of above Answer: Option C
  • 16. 8. #include<stdio.h> int main() { int a = 5; switch(a) { case 1: printf("First"); case 2: printf("Second"); case 3 + 2: printf("Third"); case 5: printf("Final"); break; } return 0; }
  • 17. A. There is no break statement in each case. B. Expression as in case 3 + 2 is not allowed. C. Duplicate case case 5: D. No error will be reported. Answer: Option C
  • 18. 9. include <stdio.h> int main() { int i=0; for(i=0; i<20; i++) { switch(i) { case 0: i+=5; case 1: i+=2; case 5: i+=5; } default: i+=4; break; } printf("%d ", i); } getchar(); return 0; OUTPUT: 21
  • 19. 10. #include<stdio.h> int main() { int i=3; switch(i) { case 1: printf("Hellon"); case 2: printf("Hin"); case 3: continue; default: printf("Byen"); } return 0; } OUTPUT: Misplaced Continue
  • 20. 11. #include<stdio.h> int main() { int i=4; switch(i) { default: printf("This is defaultn"); case 1: printf("This is case 1n"); break; case 2: printf("This is case 2n"); break; case 3: printf("This is case 3n"); } return 0; } Output: This is default This is case1
  • 21. 12. main() { float me = 1.1; double you = 1.1; if(me==you) printf("I love SWEETS"); else printf("I hate MEDICINES"); } Answer: I hate MEDICINES