From the course: Secure Coding in C (2019)
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Converting integers - C Tutorial
From the course: Secure Coding in C (2019)
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Formatting preprocessor directives1m 23s
-
(Locked)
Using an assignment as a condition1m 31s
-
(Locked)
Avoiding putchar() in a while loop1m 35s
-
(Locked)
Using the system() call1m 58s
-
(Locked)
Accessing elements beyond the array size2m 2s
-
(Locked)
Converting integers2m 26s
-
(Locked)
Looping with floating point values1m 39s
-
(Locked)
Using return values1m 58s
-
(Locked)
Confirming when EOF has been read2m 31s
-
(Locked)
Challenge: Fix the code1m 12s
-
(Locked)
Solution: Fix the code2m 12s
-
-
-
-
-