Question

How many times does the following loop execute and why? for (unsigned m = 5; --m...

How many times does the following loop execute and why?

for (unsigned m = 5; --m >= 0; )

printf(“hello\n”);

Homework Answers

Answer #1

it will run infinite time. beacuse the condition -- m>= 0 is always true . it is always true beacuse m is unsigned and it always return +ve value. .

4 byte unsigned value ranges from 0 to 4294967295

that means

unsigned 2 =2

unsigned 1 =1

unsigned 0 =0

unsigned -1 = 4294967295

unsigned -2 =4294967294

unsigned -3=4294967293

proof: -

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
IN JAVA PLEASE How many times does the while loop execute for the given input values...
IN JAVA PLEASE How many times does the while loop execute for the given input values of -1 4 0 9 userNum=3;while (userNum>0){ //Do something //Get usernum firm input }
How many times will the body of the loop be executed? var Total = 1; for...
How many times will the body of the loop be executed? var Total = 1; for (intIndex = 1; intIndex < 7 ; intIndex += 2) { Total += intIndex; }
Write a C program that prompts the user to input as many unsigned(n) as the user...
Write a C program that prompts the user to input as many unsigned(n) as the user wants to type, terminated by non negative number You may assume without checking that when the user is supposed to type an unsigned, he nevertypes a double You may assume without checking that when the user is supposed to type an unsigned, he nevertypes a negative number. For each number the user types, output whether that number is prime or not. You won't need...
java beginner level NO ARRAYS in program Flip a coin (Assignment) How many times in a...
java beginner level NO ARRAYS in program Flip a coin (Assignment) How many times in a row can you flip a coin and gets heads? Use the random number generator to simulate the flipping of the coin. 0 means heads, 1 means tails. Start a loop, flip it, if heads, count it and keep flipping. If tails, stop the loop. Display the number of times in a row that heads came up. Once this is working, wrap a while loop...
Estimate: On a typical day, how many times in the world is the English word "Hello"...
Estimate: On a typical day, how many times in the world is the English word "Hello" spoken?
Loop unroll the following MIPS code loop 4 times. Write the resulting code including any re-ordering...
Loop unroll the following MIPS code loop 4 times. Write the resulting code including any re-ordering necessary for maximum performance. loop: sw $zero, 0($s0) addi $s0, $s0, -4 bne $s0, $zero, loop
I'm trying to figure out why my program has an infinite loop. I'm pretty sure it...
I'm trying to figure out why my program has an infinite loop. I'm pretty sure it has something to do with the catch(bad_alloc) function or maybe the while (true) loop above it but I'm not sure. Can you help me figure out why i have an infinite loop and help me fix it? Thanks ---------------------------------- main.cc ---------------------------- #include #include #include #include "numbers.h" using namespace std; int main() { Numbers N1, N2;       for(size_t i = 2; i < 16;...
How long does the following piece of assembly language take to execute (assuming a 12MHz clock...
How long does the following piece of assembly language take to execute (assuming a 12MHz clock frequency)?: MOV A,#55h MUL AB JMP NEXT NEXT: MOV P2,A MOV P3, B
1. How many times the loop below will be executed? What is the value of variable...
1. How many times the loop below will be executed? What is the value of variable counter after the loop? counter = 1 while counter < 7: counter+=2 print(counter) 2. An integer is stored in a variable MyInt. Write the Python if statement to test if MyInt is even number or odd number, and print a message to show “It is even number.” or “It is an odd number”. 3. Complete the python below that asks user to enter the...
Give an example of a loop with a runtime that follows the following constraints: The loop...
Give an example of a loop with a runtime that follows the following constraints: The loop runs in O(n2) The loop runs in LaTeX: \ThetaΘ(n). Explain what the loop does, and how you derive the run time. Explain the difference between Big-Oh and Big-Theta.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT