From the course: Secure Coding in C

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Converting integers

Converting integers - C Tutorial

From the course: Secure Coding in C

Start my 1-month free trial

Converting integers

- [Instructor] Integer values come in different sizes and integers have two ranges, unsigned or a positive only range and a signed range from negative to positive values. In this source code file, all common integer data type ranges are output by using constants defined in the limits.h header file. The output is pretty much the same for all computers, but build the code on your system to verify. Or you can use those constants in your code to avoid overflows and out of range warnings. And here you see the output for this particular system. These are the ranges for integer values. Integer ranges are important to know when you convert from one integer format to another. In this code, integer values from 120 to 135 are converted to character values and then to long values. Let's build and run. And you see that the character conversion adds a sign to the value, which is inherited by the long variable in the third column. This code…

Contents