C++ Basics
C++ Basics
Introduction to
C++
Introduction to C++
C++ keywords
after Frank says 2, Peter has to keep this number in his mind.
after Frank says 5, Peter also needs to keep this number in his mind.
First number: 2
Second number: 5
Sum:
Demo Example 1
#include <iostream>
using namespace std;
int main()
{
int number_of_pods, peas_per_pod, total_peas;
cout << "Press return after entering a number.\n";
cout << "Enter the number of pods:\n";
cin >> number_of_pods;
cout << "Enter the number of peas in a pod:\n";
cin >> peas_per_pod;
total_peas = number_of_pods * peas_per_pod;
Demo Example 1
cout
cout
cout
cout
cout
cout
cout
cout
cout
<<
<<
<<
<<
<<
<<
<<
<<
<<
return 0;
}
C++ identifiers
Identifiers appear in black in Visual C++.
An identifier is a name for a variable, constant, function, etc.
It consists of a letter followed by any sequence of letters,
digits, and underscores.
Examples of valid identifiers: First_name, age,
y2000, y2k
Examples of invalid identifiers: 2000y
Identifiers cannot have special characters in them. For
example: X=Y, J-20, ~Ricky,*Michael are invalid
identifiers.
Identifiers are case-sensitive. For example: Hello,
hello, WHOAMI, WhoAmI, whoami are unique
identifiers.
C++ comments
Programming Style
C++ is a free-format language, which means
that:
Extra blanks (spaces) or tabs before or after
identifiers/operators are ignored.
Blank lines are ignored by the compiler just like
comments.
Code can be indented in any way.
There can be more than one statement on a
single line.
A single statement can continue over several
lines.
PROGRAMMER'S
DRINKING SONG!!
100 little bugs in the code,
100 bugs in the code,
fix one bug, compile it again,
101 little bugs in the code.
101 little bugs in the code
Repeat until BUGS = 0
The Internet Joke Book