Conversion Pitfalls
Overflow and truncation.
Conversions Can Bite
Silent conversions are convenient but can cause overflow, truncation, and sign surprises. This lesson covers the traps.
#include <stdio.h>
int main(void) {
printf("Beware silent conversions\n");
return 0;
}Integer Overflow
Assigning a value too large for the target integer type wraps around or loses data.
#include <stdio.h>
#include <limits.h>
int main(void) {
int max = INT_MAX;
printf("INT_MAX = %d\n", max);
return 0;
}All lessons in this course
- Implicit Conversions
- Explicit Casts
- Integer and Float Conversions
- Conversion Pitfalls