C++ PROGRAMMING
LANGUAGE
The predecessor of C++ is C, which was designed by Dennis Richie at
bell labs and first released in 1973. C is a widely used language and
was used to write the early versions of Unix and windows. Indeed, the
libraries and software-development libraries of many operating
systems are still written to have C interfaces.
In 1983, Bjarne Stroustrup released C++.
int main () The main function is the
// myby
point first program
where in C++ this is a
all C++ programs start
comment
their line. All independently
execution, lines beginning ofwith
itstwo
slash signs
location (//) are
within theconsidered comments
source code. It doesand not
matter whether
do not have thereon
any effect are other
the functions
behavior of the
with other names defined before or after it
program.
- the instructions contained within this
function's definition will always be the first
ones to be executed
#include in any C++ program.
<iostream> tells the
For that same
preprocessor toreason,
include it is iostream
the essentialstandard
that
all
coutC++<< programs
"Hello haveWorld!";
a main function.This
file. This specific file (iostream) includes the
line is a C++of
declarations statement.
the basic A statement is a
standard input-
simple or compound
output library in C++ expression that can
actually produce some effect. In fact, this
statement performs the only action that
generates a visible effect in our first
using
return
program.namespace
0; The return statement
std All the
causes
elements
the main function
of the standard
to finish.
C++
return
library
mayare
be
declared by
followed within
a return
whatcode
is called
(in our
a example
namespace,
is followed bythethenamespace
return codewith
0). the
A return
name
std. So,
code of 0
tofor
access
the main
its wefunction
declareiswith
generally
this
semicolon character (;). This expression that
interpreted as the
weprogram
will be using
worked
these
as
character is used to mark the end entities. without any errors during its
expected
Identifiers A valid identifier is a sequence of one or more
letters, digits or underscore characters (_). NOTE: RESERVED
KEYWORDS
Very important: The C++ language is a "case sensitive" language. That
means that an identifier written in capital letters is not equivalent to
another one with the same name but written in small letters. Thus, for
example, the RESULT variable is not the same as the result variable or
the Result variable. These are three different variable identifiers.
FUNDAMENTAL
DATA TYPES
declares a
variable of type
float with the
DECLARATION
identifier
mynumber.
declares a
OFint VARIABLES
variable of
with the
type
identifier a, b, c.
Global variables can be
referred from anywhere in the
code, even inside functions,
whenever it is after its
declaration.
The scope of local variables is
limited to the block enclosed in
braces ({}) where they are
declared. For example, if they
are declared at the beginning
of the body of a function (like
in function main) their scope is
between its declaration point
and the end of that function. In
the example above, this
means that if another function
existed in addition to main, the
type identifier = type identifier
initial_value ; (initial_value);
INTRODUCTION TO STRINGS
CHARACTER AND STRING
LITERALS
The first two expressions represent
single character constants, and the
following two represent string literals
composed of several characters.
Notice that to represent a single
character we enclose it between
single quotes (') and to express a
string (which generally consists of
more than one character) we enclose
it between double quotes (").
ESCAPE
CODES:
DEFINED CONSTANTS
(#define)
can define your own names for constants that you use very
often without having to resort to memory consuming
variables, simply by using the #define preprocessor
directive.
a=a+2
VALUE+= +INCREASES;
VALUE = VALUE +INCREASE
VALUE=VALUE-INCEREASE
ARITHMETIC OPERATORS
INCREASE AND DECREASE (++, --)
the value is increased before the (a++) the value stored in a is
result of the expression is increased after being evaluated
evaluated and therefore the and therefore the value stored
increased value is considered in before the increase operation is
RELATIONAL AND EQUALITY
OPERATORS
LOGICAL OPERATORS ( !, &&, || )
#include <iostream>
int main() {
int a = 5;
int b = 10;
int c = 15;
if (a > b || b < c) {
std::cout << "At least one condition is true." <<
std::endl;
} else {
std::cout << "Both conditions are false." <<
std::endl;
}
return 0;
}
-=
Int value;
Int a;
value