Joke Collection Website - Mood Talk - Two questions about C language? Please tell me the answers to these two questions and tell me why.
Two questions about C language? Please tell me the answers to these two questions and tell me why.
The first is heading D, in which there are few semicolons at the end of the sentence of printf("a=%d, b=%d\n ",A, B);
The second topic is 2345, which is in the program by default; It should be changed to the default value:
All the above are grammatical mistakes, and I corrected them myself.
The following is a specific analysis:
First question
Switch (x)
{
Case 1: // The condition is satisfied here, that is, x= 1, so execution is started.
Switch (y)
{//Here is the value for judging y..
Case 0: A++; Break; //If it is satisfied here, that is, y=0, then execute a=a+ 1, that is, a= 1. And jump out
Case1:b++; Break; //It's not executed here, because it jumps out.
}
//You can only jump out of a brace when you just break. Go here and continue execution. Because for the switch statement, as long as there is a case in front of it that meets the requirements, the statements in the case behind it will be executed until it meets the break and jumps out.
Case 2: a++;+; b++; Break; //So after the execution here, a=a+ 1, b=b+ 1, that is, a=2, b= 1, and then I saw the break and jumped out.
Case 3: a++;+; b++; //has jumped out.
}
Finally, printf outputs a=2 and b= 1.
the second question
First of all, you should understand that the characteristic of the do while statement is to execute first and then judge the condition, that is, if the condition is met, it will return to the starting position of do, if not. Jump out of the loop
do
{
Switch (k)
{Case 1: Case 3: n+=1; Break; //It should be noted that the two consecutive squares here refer to, or. That is, as long as k= 1 or 3, the condition is satisfied.
Default value: n = 0;; k-; //The default value means that none of the previous cases are correct, so it will be executed. After execution here, n=0, k- 1=4.
Case 2: Case 4: n+= 2; k-; Break; //The condition is met, so it is executed because k=4. N+2=2, k- 1=3.
}
printf("%d ",n); Output n, that is, 2
} while(k & gt; 0 & amp& ampn & lt5); If it is judged that the loop condition is met, the loop is continued from do.
do
{
Switch (k)
{Case 1: Case 3: n+=1; Break; //k=3. If the conditions are met, execute. Then n+ 1=3, jump out.
Default; n = 0; k-;
Case 2: Case 4: n+= 2; k-; Break;
} jumped out.
printf("%d ",n); Output n, that is, 3
} while(k & gt; 0 & amp& ampn & lt5); If the condition is met, continue the loop.
do
{
Switch (k)
{Case 1: Case 3: n+=1; Break; //Because k=3, it is executed. Then n=4, jump out.
Default; n = 0; k-;
Case 2: Case 4: n+= 2; k-; Break;
}
printf("%d ",n); Output n, that is, 4
} while(k & gt; 0 & amp& ampn & lt5); Satisfy, continue the cycle
do
{
Switch (k)
{Case 1: Case 3: n+=1; Break; //k=3, so execute, n+ 1=5, jump out.
Default; n = 0; k-;
Case 2: Case 4: n+= 2; k-; Break;
}
printf("%d ",n); Output n, that is, 5
} while(k & gt; 0 & amp& ampn & lt5); At this time, because n=5, the loop condition is not met and the loop is jumped out.
Finally, the program ends and outputs 2345.
If you don't understand, you can keep asking ~
- Previous article:Is Sichuan Xuboda Data Company reliable?
- Next article:The copy of the sunset is concise and atmospheric (selected 100 sentence)
- Related articles
- Sentences describing hot weather
- Starting with people with high emotional intelligence
- Talking about soaring oil prices.
- Let's talk about it when the child grows up.
- Inspirational talk about college entrance examination refueling: no matter how hard you try, you can't admit defeat and then everything will suffer.
- How to remove the back cover of the notebook?
- Talking about perfume control
- Talk about living alone. Talk about living alone.
- If you can't get it, you'd rather destroy it. Tell me.
- If you have a regret, let it go with the wind.