O'Reilly logo

Essential C++ by Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

1.1. How to Write a C++ Program

We’ve been asked to write a simple program to write a message to the user’s terminal asking her to type in her name. Then we read the name she enters, store the name so that we can use it later, and, finally, greet the user by name.

OK, so where do we start? We start in the same place every C++ program starts — in a function called main(). main() is a user-implemented function of the following general form:

int main() 
{ 
   // our program code goes here 
} 

int is a C++ language keyword. Keywords are predefined names given special meaning within the language. int represents a built-in integer data type. (I have much more to say about data types in the next section.)

A function is an independent code sequence that ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required