[C] an unsigned short basic language for a difficult cycle

I was in my knowledge of the planet: "C language classroom doubts" in the first chapter raised a question: [the first one] [C programming language] [unsigned short type for a difficult cycle]
To see more of C language difficulties or need to resolve the questions of the students, the micro end of the letter I sweep the text of the planet two-dimensional code to join it!

First, [the problem]

Students, today Road C language more interesting question, C program code shown below.

for loop I gave an initial value of the variable para 1, let para increment 1, but the conditions for the end of the cycle is not specified. Do you think there is something wrong? Will it be a endless cycle? If you have questions how are you going to amend it?

Second, the [doubts]

This loop will terminate and will not loop forever.

On my PC, I use sizeof obtained the "unsigned short" type variable is occupied by two bytes, so the range is "0-65535." In this procedure C, the initial value of an unsigned short variable is para 1, as long as it is not 0, for loop would have been executed.

After the printf function After each execution, the variable will increment para 1, para increment up to 65535, this time variable para 1 plus you do not think that will become 65536! You have to know at this time variable para overflow, and back to the minimum point value range: 0.

Variable para 0, then the time for the cycle is over, that is to say printf function outputs 1-65535 end of the program!

Three, "C language classroom doubts" Planet adding card

Click this link to join the micro-channel sweep!

 

Guess you like

Origin www.iteye.com/blog/kelehaier-2443679