0% found this document useful (0 votes)
56 views1 page

Professional C++ 51-72-2

This document introduces the basics of C++ and provides a simple "Hello World" example program to demonstrate key concepts. The "Hello World" program prints the message "Hello World!" using input/output streams. It shows important elements like comments, preprocessor directives, the main function, and I/O streams. C++ is described as a "better C" or "superset of C" that addresses some issues in C while maintaining a similar syntax that C programmers will find familiar.

Uploaded by

Percy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views1 page

Professional C++ 51-72-2

This document introduces the basics of C++ and provides a simple "Hello World" example program to demonstrate key concepts. The "Hello World" program prints the message "Hello World!" using input/output streams. It shows important elements like comments, preprocessor directives, the main function, and I/O streams. C++ is described as a "better C" or "superset of C" that addresses some issues in C while maintaining a similar syntax that C programmers will find familiar.

Uploaded by

Percy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

4╇ ❘╇ CHAPTER 1╇ A Crash Course in C++ and the STL

C++, read this chapter carefully and make sure you understand the examples. If you need additional
introductory information, consult the titles listed in Appendix B.

THE BASICS OF C++


The C++ language is often viewed as a “better C” or a “superset of C.” Many of the annoyances or
rough edges of the C language were addressed when C++ was designed. Because C++ is based on
C, much of the syntax you’ll see in this section will look familiar to you if you are an experienced
C programmer. The two languages certainly have their differences, though. As evidence, The
C++ Programming Language by C++ creator Bjarne Stroustrup (Fourth Edition; Addison-Wesley
Professional, 2013), weighs in at 1,368 pages, while Kernighan and Ritchie’s The C Programming
Language (Second Edition; Prentice Hall, 1988) is a scant 274 pages. So if you’re a C programmer,
be on the look out for new or unfamiliar syntax!

The Obligatory Hello, World


In all its glory, the following code is the simplest C++ program you’re likely to encounter:
// helloworld.cpp
#include <iostream>
int main()
{
std::cout << "Hello, World!" << std::endl;
return 0;
}

This code, as you might expect, prints the message “Hello, World!” on the screen. It is a simple
program and unlikely to win any awards, but it does exhibit the following important concepts about
the format of a C++ program.
➤➤ Comments
➤➤ Preprocessor Directives
➤➤ The main() Function
➤➤ I/O Streams
These concepts are briefly explained in the next sections.

Comments
The first line of the program is a comment, a message that exists for the programmer only and is
ignored by the compiler. In C++, there are two ways to delineate a comment. In the preceding and
following examples, two slashes indicate that whatever follows on that line is a comment.
// helloworld.cpp

The same behavior (this is to say, none) would be achieved by using a multiline comment. Multiline
comments start with /* and end with */. The following code shows a multiline comment in action
(or, more appropriately, inaction).

c01.indd 4 11-08-2014 10:28:45

You might also like