Skip to Content
C++程序设计:原理与实践(基础篇)(原书第2版)
book

C++程序设计:原理与实践(基础篇)(原书第2版)

by 本贾尼 斯特劳斯特鲁普
August 2021
Intermediate to advanced
450 pages
9h 36m
Chinese
Pearson
Content preview from C++程序设计:原理与实践(基础篇)(原书第2版)

2.1 程序

为了使计算机能够做某件事,你(或其他某人)需要明确告诉它怎么做——细致到那些繁琐的细节。这种对“怎么做”的描述被称为程序,编程是书写和测试程序的行为。

在某种意义上,我们都编过程序。毕竟,我们都曾被告知完成某些任务的步骤,例如“如何开车去最近的电影院”“如何找到楼上的浴室”和“如何用微波炉热饭”。这种描述和程序之间的不同表现在精确度上:人类间的指示常常是不精确的,但我们可以通过常识加以弥补,但是计算机无法做到。例如,对如何找到楼上的浴室,“沿走廊右转,上楼,它位于你的左边”可能是很好的描述。但是,当你仔细看这些简单的指令,会发现其中语法的草率和指令的不完整。人类很容易做出弥补。例如,假设你坐在桌子旁问浴室的方向。你不需要被告知离开桌子来到走廊、绕过(不是跨过或钻过)桌子、不要踩到猫等。你不需要被告知不要带走刀子和叉子,以及记住打开灯才能看到楼梯。你也不需要被告知进入浴室之前首先要开门。

与此相反,计算机是非常笨拙的。它们做的所有事都要准确、详细地描述。我们考虑“沿走廊右转,上楼,它位于你的左边”。走廊在哪里?什么是走廊?什么是“右转”?什么是楼梯?我如何上楼梯?(每次迈出一步?两步?沿扶手滑上楼梯?)什么在我的左边?它什么时候会在我的左边?为了向计算机精确描述这些“事情”,我们需要一种由特定语法精确定义的语言(对此目标来说英语的结构太过松散了)和针对我们要执行的多种行动明确定义的词汇。这样的语言被称为编程语言,C++就是为各种编程任务设计的编程语言。

如果你想知道有关计算机、程序和编程的更多哲学上的细节,请(重新)阅读第1章。在本章中,让我们来看一些代码,从一个很简单的程序和运行它的工具和技术开始学习。

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

C++语言导学(原书第2版)

C++语言导学(原书第2版)

本贾尼 斯特劳斯特鲁普
管理Kubernetes

管理Kubernetes

Brendan Burns, Craig Tracey
Python编程入门与实战

Python编程入门与实战

Posts & Telecom Press, Fabrizio Romano

Publisher Resources

ISBN: 9787111562252