  # What is a cyclic property of data type in c? Explain with any example.

+1 vote
1,946 views
What is a cyclic property of data type in c? Explain with any example. posted Jun 3, 2015

In C for some data types, when we assign a value beyond range of that data type then it won't give any compiler error but assign a number according to some cyclic order. This is known as cyclic nature of data type.
only
char
int
long int
supports cyclic nature.

For example lets see how it happens in char both signed and unsigned.
Range of unsigned char is 0 to 255
0 1 2 3 4 ...... .... .... 255
----------------------------> (clock wise, i.e after 255 it will be 0, 1 and so on)
<--------------------------- (anti clock wire i.e after 0 it will be 255 , 254 and so on)
So if we assign the a value greater than 255 then value of variable will be changed to a value if we will move clockwise direction
If number is less than 0 then move in anti clockwise direction.

You can use this formula to validate:

``````If number is X and its greater than 255 then
New value = X % 256
If number is Y and its less than 0 then
New value = 256 – (Y% 256)
``````

For sign char its range is -128 to 127

`````` If number is X and  its greater than 127 then
p = X % 256
if p <=127
New value = p
else
New value = p – 256
If number is Y and its less than -128 then
p = Y % 256
If p <= 127
New value = -p
else
New value = 256 -p
`````` answer Jun 4, 2015
``````#include<stdio.h>
int main(){
signed char c1=130;
signed char c2=-130;
printf("%d  %d",c1,c2);
return 0;
}
``````

### Output: -126 126 (why?)

This situation is known as overflow 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 we will assign a number which is less than -128 then we have to move in anti-clockwise direction. answer Jun 8, 2015
Similar Questions
``````void main(){