C in 100 Seconds: Type Casting — Why 7/2 Is 3 and How to Fix It | Episode 15
2views
002:25
T
Taught by Celeste AI - AI Coding Coach
View on YouTubeDescription
Seven divided by two is three — not three point five. Both are ints, so C drops the decimal. Cast one side to float and you get the real
answer.
Going the other way, casting a double to int chops off everything after the decimal point. No rounding, just truncation. And every char is
secretly an integer — capital A is sixty-five. The parentheses force the conversion. Know when C does it for you and when you need to be
explicit.
Student code: https://github.com/GoCelesteAI/c-in-100-seconds/tree/main/episode15
What You'll Learn:
• Explicit casting with (float) and (int)
• Why int / int drops the decimal
• Truncation — double to int loses everything after the point
• char is an int — A equals 65 in ASCII
• Implicit vs explicit type conversion
Next: Episode 16 — Header Files
#c #programming #100seconds #learnc #typecasting #truncation #ascii #implicit #explicit #tutorial
Tags
c type casting, implicit cast c, explicit cast c, truncation c, ascii c, float to int, int division fix, c tutorial 2026, c beginner, 100
seconds, learn c, coding tutorial
Tags
c type castingimplicit cast cexplicit cast ctruncation cascii cfloat to intint division fixc tutorial 2026c beginner100 secondslearn ccoding tutorial