C++ Brain Teasers: Exercise Your Mind
暫譯: C++ 腦筋急轉彎:鍛鍊你的思維
Knatten, Anders Schau
- 出版商: Pragmatic Bookshelf
- 出版日期: 2024-07-09
- 售價: $1,400
- 貴賓價: 9.5 折 $1,330
- 語言: 英文
- 頁數: 140
- 裝訂: Quality Paper - also called trade paper
- ISBN: 9798888650516
- ISBN-13: 9798888650516
-
相關分類:
C++ 程式語言
立即出貨 (庫存=1)
相關主題
商品描述
C++ is famous for getting all the default behaviors wrong and for sometimes making demons fly out of your nose. Through 25 puzzles, from the useful to the outright weird, we explore some of C++'s most interesting quirks. How does initialization actually work? Do temporaries even exist? Why is +!!"" a valid expression in C++? As you work through each puzzle, you will peel off some of the layers of complexity of C++, getting a fundamental understanding of how the language works. This will help you write better code and recognize issues more easily while debugging.
Each puzzle in the book is a complete, seemingly simple C++ program, but can you figure out the output for each, or will the answers stump you? Most of the programs compile and have deterministic, though sometimes surprising, output. Some might, however, have undefined behavior, where anything can happen, including making demons fly out of your nose! Yet others might have unspecified behavior with output that is not completely deterministic; we just know nothing as bad as nasal demons will happen.
All puzzles are accompanied by detailed discussions, taking a look under the hood at what exactly is going on to help you understand more about C++'s unexpected behaviors, as well as fundamental concepts like initialization, overload resolution, and implicit conversions. For the non-deterministic cases, we'll explore some typical behaviors one can expect to see in practice, what causes them, and why they shouldn't be relied on.
After working through the book, you'll have tools and techniques to help you write better and safer code, and a better understanding of the fundamentals of the language, the background for some of C++'s apparent weirdness, and a better feel for identifying bugs and unsafe code in your own programs.
What You Need:
The book assumes basic knowledge of C++. If you want to run the programs yourself, you can use either a local C++ compiler or the online compilers at https: //godbolt.org.
商品描述(中文翻譯)
C++ 以其預設行為的錯誤而聞名,有時甚至會讓惡魔從你的鼻子裡飛出來。透過 25 道謎題,從實用到奇特,我們探索 C++ 最有趣的特性。初始化實際上是如何運作的?臨時變數真的存在嗎?為什麼 +!!'' 在 C++ 中是一個有效的表達式?當你逐一解決每個謎題時,你將逐步揭開 C++ 的複雜性,對這門語言的運作有基本的理解。這將幫助你寫出更好的程式碼,並在除錯時更容易識別問題。
書中的每個謎題都是一個完整的、看似簡單的 C++ 程式,但你能找出每個程式的輸出嗎?還是答案會讓你困惑?大多數程式可以編譯並且有確定性,雖然有時會令人驚訝的輸出。然而,有些程式可能會有未定義的行為,任何事情都有可能發生,包括讓惡魔從你的鼻子裡飛出來!而其他程式可能會有未指定的行為,輸出並不完全確定;我們只知道不會發生像鼻子裡的惡魔那樣糟糕的事情。
所有謎題都附有詳細的討論,深入探討發生了什麼,以幫助你更了解 C++ 的意外行為,以及初始化、重載解析和隱式轉換等基本概念。對於非確定性的情況,我們將探討一些在實踐中可以預期的典型行為,造成這些行為的原因,以及為什麼不應依賴它們。
在完成這本書後,你將擁有幫助你寫出更好、更安全程式碼的工具和技術,並對這門語言的基本概念有更深入的理解,了解 C++ 明顯奇特之處的背景,並更好地識別自己程式中的錯誤和不安全的程式碼。
你需要的:這本書假設你對 C++ 有基本的了解。如果你想自己運行程式,可以使用本地的 C++ 編譯器或訪問 https://godbolt.org 的線上編譯器。