What is the output from the following code segment? Assuming that the bits in an
ID: 3725727 • Letter: W
Question
What is the output from the following code segment?
Assuming that the bits in an integer are numbered from 0, from right (least significant) to left (most significant), write an expression using bitwise logical operators to extract the 4 bits numbered 6 to 3 from an integer i1, and shift them all down so that bit numbered 3 ends up in position number 1.
Explain how a conditional expression may be rewritten using an if-then-else statement.
Rewrite the following for loop as a while loop.i
Rewrite the following while loop as a for loop.
Explain the difference between continue and break statements.
What is the output from the following code segment?
Explanation / Answer
Conditional statement can be rewritten as if then else statement as below:
Let's say we have
z = a > b ? a : b;
Now here z will have a if a>b else it will get b
So it can be rewritten as
if(a>b)
{z=a;
}
else
{
z=b;
}
Rewrite for loop into while
int Index = 1;
while(Index<MAX)
{
printf("%d ",Index);
Total+= Index;
Index++;
}
Rewrite while loop into for
for(int Index=1;Index<Max; Index++)
{
printf("%d ",Index);
Total+=Index;}
The output is
15
31
continue statement is : it continues to next iteration of the loop.
break statement is: it breaks from the iteration and exits the loop.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.