C++ Brain Teasers : Exercise Your Mind (Paperback)
暫譯: C++ 腦筋急轉彎:鍛鍊你的思維 (平裝)

Knatten, Anders Schau

  • 出版商: Pragmatic Bookshelf
  • 出版日期: 2024-07-09
  • 售價: $1,540
  • 貴賓價: 9.5$1,463
  • 語言: 英文
  • 頁數: 140
  • 裝訂: Quality Paper - also called trade paper
  • ISBN: 9798888650516
  • ISBN-13: 9798888650516
  • 相關分類: C++ 程式語言
  • 海外代購書籍(需單獨結帳)

買這商品的人也買了...

商品描述

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 的線上編譯器。