use the code to fill in the values. Use a ? if the value is not determined by th
ID: 3598085 • Letter: U
Question
use the code to fill in the values. Use a ? if the value is not determined by the code. If a character is stored use ' 's about the character value. int h = 0, n = 0, s = 0, y = 0; char ch;
switch (ch) { case 'k' : ++h; break;
case 'p' : ++n;
case 's' : ++s;
default : ++y; }
/* In each part below, start with the initial values */
a. if value of ch is 'k' h ____ n ____ s ____ y ____
b. if value of ch is 'p' h ____ n ____ s ____ y ____
c. if value of ch is 's' h ____ n ____ s ____ y ____
d. if value of ch is 'h' h ____ n ____ s ____ y ____
Explanation / Answer
Here is your Answer:
Answer:
a.If value of ch is ‘k’ then value of h=1 ,n=1, s=1, y=1
Reason: First control will go to case ‘k’ and increment value of h and there is no break statement so it will go through every case below it and perform there action.
b.If value of ch is ‘p’ then value of h=0,n=1,s=1,y=1
Reason: First control will go to case ‘p’ and increment value of n and there is no break statement so it will go through every case below it and perform there actions.
c.If value of ch is ‘s’ then value of h=0,n=0,s=1,y=1
Reason: First control will go to case ‘s’ and increment value of s and there is no break statement so it will go through every case below it and perform there actions.
d.If value of ch is ‘h’ then value of h=0,n=0,s=0,y=1
Reason: There is no case ‘h’ so it will go to default case and only update y value.
I hope this solves your problem
Comment if you have any problem in above answer
And please give it a thumbs up if it solved your problem :)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.