In this blog |
---|
how ranges work with eg |
simple question |
eg1
so lets take eg of integer data type:
this program will work fine but what if i exceed the range of integer which is -2,147,483,648 to 2,147,483,647 (in case of 64 bit compiler)
so some garbage value will be printed ,what if i say we can predict that value (whoooooooooooo)
but how ?
so there is some sequence in prediction so i had taken the ranges beside the circle and we name it as %d circle ( for convinience take +ve ranges in clock wise and -ve in anti-clock wise)
(note: these dots represent ranges )
so we will go on counting the range starting form 0 then 1 until the we had counted 2147484648 values on the circle in the side they increment (why this because you had initialize the variable with +ve value ,(in case of -ve values you start form 0 and go on decrementing side) ,so our final answer is -2,147,483,648
eg 2
now lets take eg of unsigned integer which is having only +ve ranges only 0 to 4,294,967,295 , now lets take the circle again ,now with the name %u circle
so now what if i assignee a -ve value to variable
so it will start counting in the direction opposite of ( 0 1 2 3 )
so before 0 there is -1 if we count but the value we get is 4,294,967,295
so our final answer is 4,294,967,295.
(note: when you move over a circle , just keep in mind the you not initialize variable a value which again crosses or stop at 0 as it will give you warning, eg :4294967296 in case of unsigned int)
Q.)now here is an exercise for you what will be the -2,147,483,652 value in case of unsigned?
comment down below the answer ,or suggestion or any doubt ,thank for reading ..😀
No comments:
Post a Comment