C++ Intro
C ++
A C++ program is a collection of one or more functions.
There must be a function called main (). Execution always begins with the
first statement in function main ().
Any other functions in your program are subprograms and are not
executed until they are called.
// Hello World C++ program Comment
// from Eclipse IDE Comment
#include < iostream> preprocessor directive
using namespace std; which namespace to use
int main () beginning of function named main ()
{ output statement
cout << Hello World!; string literal
return 0; send 0 to operating system
} end of block for main
When a line begins with a # it indicates its a preprocessor directive.
The preprocessor reads your program before it is compiled and only
executes lines begging with #.
#include directive causes the preprocessor to include the contents of
another file, AKA header file, in the program.
Its called header file because it should be included at the top of the
program.
The enclosed brackets < iostream> is the name of the header file to be
included. (The name is iostream, the brackets indicate that its a standard
C++ header file)
iostream file contains code that allows a C++ program to display output
on the screen and read input from the keyboard.
We need to include this file because the cout statement prints output to
the computer screen.
C++ uses namespaces to organize the names of program entities.
The statement using namespace std; declares that the program will be
accessing entities whose names are part of the namespace called std.
A function can be thought of as a group of one or more
programming statements that has a name.
The name of this function is main, and the set of parentheses that
follows the name indicates that its a function.
The word int stands for integer. It indicates that the function sends
an integer value back to the operating system when it is finished
executing.
Every C++ program must have a function called main. Its the starting
point of the program.
The function main is ALWAYS int main ()
C++ is a case-sensitive language. It regards uppercase letters as being
entirely different characters than their lowercase counterparts.
All statements that make up a function are enclosed in a set of
{braces}. Everything between 2 braces is the contents of the function
main.
Phases, words, or sentences inside the quotation marks is called a
string, string constant, or string literal.
cout is the only line in the program that causes anything to be printed on
the screen.
A semicolon ; is required to mark the end of a complete statement.
return 0 sends the integer value 0 back to the operating system when the
program finishes running. The value 0 usually indicates that a program
executed successfully.
This statement is always necessary in the main function.
Special Character s
// Beginning of a comment
# Beginning of preprocessor
< > Encloses file name in #include
( ) Used when naming a function
{ } Encloses a group of statements
Encloses string of characters
; End of a programming statement