SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances (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
 

En vedette

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 statementRaj Parekh
 
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)choksheak
 
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 machineAmal Shajan
 
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 Hardslls01
 
Routing Protocols and Concepts - Chapter 1
Routing Protocols and Concepts - Chapter 1Routing Protocols and Concepts - Chapter 1
Routing Protocols and Concepts - Chapter 1CAVC
 
Power electronic drives ppt
Power electronic drives pptPower electronic drives ppt
Power electronic drives pptSai Manoj
 
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 routerAkmal Cikmat
 
Katalog Wiosna Lato 2017 - Conhpol Elite
Katalog Wiosna Lato 2017 - Conhpol EliteKatalog Wiosna Lato 2017 - Conhpol Elite
Katalog Wiosna Lato 2017 - Conhpol EliteConhpolElite
 

En vedette (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
 

Similaire à Switch statement mcq

Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02CIMAP
 
C interview question answer 2
C interview question answer 2C interview question answer 2
C interview question answer 2Amit Kapoor
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in Csana shaikh
 
c interview progs.pdf
c interview progs.pdfc interview progs.pdf
c interview progs.pdfpooja82042
 
Technical aptitude Test 1 CSE
Technical aptitude Test 1 CSETechnical aptitude Test 1 CSE
Technical aptitude Test 1 CSESujata Regoti
 
Learning C programming - from lynxbee.com
Learning C programming - from lynxbee.comLearning C programming - from lynxbee.com
Learning C programming - from lynxbee.comGreen Ecosystem
 
C aptitude.2doc
C aptitude.2docC aptitude.2doc
C aptitude.2docSrikanth
 
Programming basics
Programming basicsProgramming basics
Programming basics246paa
 
C aptitude scribd
C aptitude scribdC aptitude scribd
C aptitude scribdAmit Kapoor
 
Very interesting C programming Technical Questions
Very interesting C programming Technical Questions Very interesting C programming Technical Questions
Very interesting C programming Technical Questions Vanathi24
 
Decision statements in c laguage
Decision statements in c laguageDecision statements in c laguage
Decision statements in c laguageTanmay Modi
 

Similaire à 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
 

Plus 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
 

Dernier

Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
Comparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization TechniquesComparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization Techniquesugginaramesh
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...121011101441
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleAlluxio, Inc.
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 

Dernier (20)

Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
Comparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization TechniquesComparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization Techniques
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at Scale
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 

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