How to find the digits truncation when assigning the
interger variable to the character variables.

like int i=500; char x = i : here we have truncation. how to
find this.

another ex: i =100; char x=i. here we do not have
truncation.

Answer Posted / ashu

when i=500 in int which means it is not going beyond the limit of integer range in memory but when x=i which means we are assigning value of i to x.. that is now x becomes 500 whose data type is "char" and range is only -128 to 127 in signed & 0 to 255 in unsigned.. i.e. it is crossing the range.. there we find truncation here

where as in 2nd ex: i=100 which then x=i in char datatype that is char x variable is assigned with i=100 which is not byond range of char data type..therefor no truncation in this example we can find.

Is This Answer Correct ?    3 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is nested structure with example?

616


What is the use of linkage in c language?

611


What are the types of arrays in c?

618


Explain is it valid to address one element beyond the end of an array?

728


What is selection sort in c?

601






What language is windows 1.0 written?

570


What are the 5 data types?

594


What do the functions atoi(), itoa() and gcvt() do?

722


explain what is an endless loop?

607


Why should I prototype a function?

629


What is file in c preprocessor?

646


What is the acronym for ansi?

622


A program is required to print your biographic information including: Names, gender, student Number, Cell Number, line of study and your residential address.

1244


Why c is called a mid level programming language?

599


What is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?

619