惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Vercel News
Vercel News
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The GitHub Blog
The GitHub Blog
N
Netflix TechBlog - Medium
MyScale Blog
MyScale Blog
F
Fortinet All Blogs
Microsoft Azure Blog
Microsoft Azure Blog
H
Help Net Security
C
Check Point Blog
博客园 - 聂微东
云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
U
Unit 42
WordPress大学
WordPress大学
B
Blog
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
T
Tailwind CSS Blog
D
DataBreaches.Net
G
Google Developers Blog
T
The Blog of Author Tim Ferriss
Hugging Face - Blog
Hugging Face - Blog
IT之家
IT之家

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
🕵️‍♂️ The Case of the Vanishing Digits: Why 123,456 = 64?
Laiba · 2026-04-27 · via DEV Community

Laiba

Ever had a piece of code do something so weird you thought your computer was possessed? 👻

Check out this C++ mystery:

char ch = 123456;
cout << (int)ch; 
// Output: 64 🤯

Enter fullscreen mode Exit fullscreen mode

That is a great idea! Acknowledging the mentors who helped you understand a concept adds a nice personal touch and builds community. Since you're currently working through his DBMS playlist and following his roadmap, it fits perfectly.

Here is the updated version with a "Shoutout" section included at the end:


🕵️‍♂️ The Case of the Vanishing Digits: Why 123,456 = 64?

Ever had a piece of code do something so weird you thought your computer was possessed? 👻

Check out this C++ mystery:

char ch = 123456;
cout << (int)ch; 
// Output: 64 🤯

Enter fullscreen mode Exit fullscreen mode

Wait... what? Where did the other 123,392 go? Did the compiler steal them? 💸

Actually, it’s all about "The Teacup Rule."


1. The Container Problem 📦

Think of a char as a tiny teacup. It can only hold 8 bits of data.

The number 123,456 is like a gallon of water. When you try to pour a gallon into a teacup, you don't get a gallon-sized teacup... you just get a mess on the floor and a very full cup.

2. The "Binary Guillotine" ✂️

Computers see numbers in binary (1s and 0s). Let’s look at what happened under the hood:

  • 123,456 in binary is: 1 11100010 01000000 (17 bits long!)
  • A char only has room for the last 8 bits.

So, C++ acts like a guillotine and chops off everything that doesn't fit:
Discarded: 1 11100010
Kept: 01000000

3. The Math Magic ✨

When we translate those leftover bits (01000000) back into a decimal number, we get:
$2^6 = 64$

That’s why your output is 64! The computer didn't make a mistake; it just followed your instructions to squeeze a giant into a tiny box. 🧳


💡 The Takeaway

This is called Data Truncation. It’s a classic "gotcha" in programming.

Pro-Tip: If you’re expecting big numbers, stay away from char. Use int or long long instead! Otherwise, your data might just "overflow" onto the floor. 🌊


🙌 A Special Shoutout

I want to give a huge thanks to Love Babbar! 🚀 His amazing teaching style and structured roadmaps have been a massive help in my journey of mastering these foundational concepts. If you're diving into DSA or DBMS, his content is a goldmine!


🛠️ Quick Challenge

If you change the code to cout << ch; (without the int part), you’ll see the @ symbol. Why? Because 64 is the ASCII code for the @ sign! 📧

Have you ever run into a bug where your numbers mysteriously changed? Let me know in the comments! 👇