In C some data types shows one special properties that when we assign a value beyond range of that data type then it will not any compiler error but assign a number according to some cyclic order. This property is known as cyclic nature of data type.

Data type which shows cyclic nature:

(a) char

(b) int

(c) long int

Data type which doesn’t show cyclic nature:

(a) float

(b) double

(c) long double

**1. Cyclic nature of**

**unsigned**

**char**:

Range of unsigned char is 0 to 255. If we will assign a value greater than 255 then value of variable will be changed to a value if we will move clockwise direction as shown in the figure according to number. If number is less than 0 then move in anti clockwise direction.

**Short cut formula to find cyclic value:**

**If number is X where X is greater than 255 then**

**New value = X % 256**

**If number is Y where Y is less than 0 then**

**New value = 256 – (Y% 256)**

2. Cyclic nature of signed

2. Cyclic nature of signed

**char**:

Range of unsigned char is -128 to 127. If we will assign a value greater than 127 then value of variable will be changed to a value if we will move clockwise direction as shown in the figure according to number. If number is less than -128 then move in anti clockwise direction.

**Short cut formula to find cyclic value:**

**If number is X where X is greater than 127 then**

**p = X % 256**

**if p <=127**

**New value = p**

**else**

**New value = p – 256**

**If number is Y where Y is less than -128 then**

**p = Y % 256**

**If p <= 127**

**New value = -p**

**else**

**New value = 256 -p**

**3. Cyclic nature of**

**unsigned**

**int**:

Range of unsigned int is 0 to 65535. If we will assign a value greater than 65535 then value of variable will be changed to a value if we will move clockwise direction as shown in the figure according to number. If number is less than 0 then move in anti clockwise direction.

**Short cut formula to find cyclic value:**

**If number is X where X is greater than 65535 then**

**New value = X % 65536**

**If number is Y where Y is less than 0 then**

**New value = 65536– (Y% 65536)**

**4. Cyclic nature of**

**signed**

**int**:

Range of unsigned int is -32768 to 32767. If we will assign a value greater than 32767 then value of variable will be changed to a value if we will move clockwise direction as shown in the figure according to number. If number is less than -32768 then move in anti clockwise direction.

**If number is X where X is greater than 32767 then**

**p = X % 65536**

**if p <=32767**

**New value = p**

**else**

**New value = p - 65536**

**If number is Y where Y is less than -32768 then**

**p = Y % 65536**

**If p <= 32767**

**New value = -p**

**else**

**New value = 65536 -p**

Note: Same rule is also applicable in case of signed long int and unsigned long int.

## 10 comments:

#include

#include

void main()

{

char a=200;

pintf("%d",a);

getch();

}

o/p is -56...how????plzz explain.....

Inwhich category he comes 1,2,3

subtract 127 from 200 and add result to -128... u vl get -56 as ans coz of cyclic property.

u didn't specify whether a is signed or unsigned so by default compiler is taking it as signed...

Really very good and easy to understand

hey,it was very helpful.but you wrote 653535 instead of 65535 in point 3 and ubsigned instead of signed in point 4.:)

Thanks a ton for posting good questions that help widen our understanding of how computers work

Awesome explanation.....a ton of thanks to u .....it greatly helped me understand C

Int main()

{

Char str1[]="pratik";

Char str2[]="pratik";

If(str1==str2)

print("equal\n");

else

printf("unequal\n");

return 0;

}

What will be the output??

Int main()

{

Char str1[]="pratik";

Char str2[]="pratik";

If(str1==str2)

print("equal\n");

else

printf("unequal\n");

return 0;

}

What will be the output??

Unequal is the answer bcoz in the line of char str1[]="pratik" the compiler does not know whether after the word pratik there is \o or not

Great content and it is really innovative to everyone.

spanish language in chennai

spanish courses in chennai

TOEFL Classes in Chennai

French Language Classes in Chennai

pearson vue test center in chennai

German Language Course in Chennai

French Classes in anna nagar

spoken english in anna nagar

Post a Comment