跪拜 Guibai
← All articles
Programmer

The '烫烫烫' Mystery and Other C/C++ Beginner Traps: Full-Width Characters, Memory Layout, and Encoding Mismatch

By hzy26_11 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

The '烫烫烫' overread and the UTF-8/GBK console mismatch are two of the most common panics for anyone new to C/C++ on Windows; knowing that 0xCC renders as '烫' and that chcp 65001 flips the console to UTF-8 eliminates hours of confusion. The bootcamp debt note also shows a real pressure point in Chinese CS education that shapes how much self-study content like this gets produced.

Summary

Full-width vs half-width characters trip up C/C++ beginners the moment a Chinese punctuation mark slips into code. The compiler sees an invalid character, throws C3872, and the fix is simply knowing which byte width the compiler expects. ASCII only covers 128 standard and 256 extended positions; a Chinese char like '中' occupies 2 to 3 bytes and never fits in a char, so the rule that "single quotes contain exactly one character" only holds for single-byte cases.

The memory distinction between 'A' and "A" is concrete: one byte containing 65 versus two bytes containing 65 then 0. Strings carry a hidden \0, so sizeof("Hello") returns 6 while strlen returns 5. Multi-character constants like 'AB' compile but their value depends on the compiler, a non-portable practice that should be avoided. In VS, uninitialized stack memory is filled with 0xCC, which GBK decodes as '烫'—that's why an unterminated string print produces a flood of '烫烫烫' before running into the next string's \0.

Windows console encoding defaults to GBK (code page 936) while VS saves source as UTF-8, so Chinese output turns into garbage. Forcing chcp 65001 at the top of main switches the console to UTF-8 and fixes it. The notes also cover the solution vs project distinction in VS, line number settings, and the compile-link pipeline from .c to .exe. The author ends with a personal note: a 10,000+ RMB bootcamp course paid in 24 installments, taken on the eve of a junior college internship, without telling his parents.

Takeaways
— Single-quoted 'A' occupies 1 byte (value 65); double-quoted "A" occupies 2 bytes (65 plus a null terminator).
— C string literals always end with an implicit \0; sizeof includes it, strlen stops counting at it.
— Multi-character constants like 'AB' are compiler-dependent and non-portable; avoid them.
— In pure C, a character constant has type int and occupies 4 bytes, but truncates when assigned to a char variable.
— Standard ASCII has 128 characters, extended has 256; a Chinese character needs 2-3 bytes and cannot fit in a single char.
— VS Debug mode fills uninitialized stack memory with 0xCC, which GBK decodes as the character '烫'.
— The \n in printf is only a formatting control; it does not stop string reading, so out-of-bounds reads can run into adjacent strings.
— VS saves source as UTF-8, but the Windows console defaults to GBK code page 936, causing garbled Chinese output.
— Running system("chcp 65001 > nul") at the start of main switches the console to UTF-8.
— A VS solution (.sln) is a container for projects; placing them in the same directory works best for simple single-file projects.
— Compilation flow: .c source to .obj via cl.exe, then linking with .lib to produce an .exe.
Conclusions

The 0xCC-initialization behavior is a debugger artifact, not a language rule, but it gives C/C++ beginners a memorable first encounter with memory layout and undefined behavior.

Encoding mismatch between editor and console remains a recurring pain point for developers on Windows; chcp 65001 is a pragmatic bandage that many production codebases still rely on.

The personal debt disclosure—10,000+ RMB, 24 interest-free installments, kept from parents—suggests that self-funded bootcamps are a significant financial route for vocational college students entering CS jobs in China.

The manual's style of mixing compiler trivia with practical VS settings reflects a wider Chinese tutorial culture that values immediate, low-level explanations over abstract theory.

Concepts & terms
Multi-character constant
A sequence of characters inside single quotes, like 'AB', whose value is compiler-defined (usually by concatenating ASCII codes). It is non-portable and considered a bad practice in C/C++.
Full-width vs half-width
Half-width characters occupy one byte (standard ASCII); full-width characters occupy two bytes in encodings like GBK or Unicode. Compilers enforce this distinction strictly, so Chinese punctuation causes errors like C3872.
chcp 65001
A Windows command that changes the console code page to UTF-8. It is used in C programs via system("chcp 65001 > nul") to prevent garbled Chinese output when the console defaults to GBK (code page 936).
0xCC stack initialization
In Visual Studio Debug builds, uninitialized stack memory is filled with 0xCC. Under GBK encoding this byte maps to the character '烫', so a missing null terminator causes printed output to show a trail of '烫烫烫'.
Solution and Project
A Visual Studio solution (.sln) is a top-level container managing one or more projects. A project builds to a single output like an .exe. Unchecking "place solution and project in the same directory" creates nested paths useful for large multi-project codebases.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗