You are on page 1of 2

IntroductiontoC++ It may even make the compiler re-run a specific piece

again, or just skip a bunch of code.


Introduction
C++ is a powerful general-purpose programming language. 3. C++ Data Structure - a group of data elements grouped
It can be used to develop operating systems, browsers, together under one name. Allows you to combine data
games, and so on. C++ supports different ways of items of different kinds.
programming like procedural, object-oriented, functional,
and so on. This makes C++ powerful as well as flexible 4. C++ Syntax - a layout of words, expression, and symbols.
They are some well-defined set of rules that allow you to
I. What is C++? create some piece of well-functioning software.
C++ is a general-purpose object-oriented programming
language. It was created by Bjarne Stroustrup at Bell Labs 5. C++ Tools - is some piece of software which when used
circa 1980 with the code allows you to program faster. IDE is a
software which will make your coding life so much easier.
C++ is a cross-platform language that can be used to create
high-performance IV. Features of C++
applications C++ is Fast - Since, C++ is an extended version of C, the C
part of it is very low level. This offers a huge boost in speed
Some call C++ “C with classes” because it introduces object that high level languages like Python, Java don’t give you.
oriented programming principles, including the use of
defined classes, to the C programming language framework C++ is Statically Typed - In simple terms, C++ doesn’t allow
the compiler to make assumptions about the type of data
C++ is considered an intermediate-level language, as it e.g. 10 is different from “10” and you have to let C++
includes both high and low- level language features. know which one you are talking about.

II. Quick Facts Regrading C++ Object oriented programming with C++ - With its use in C+
C++ ranks 4th in popularity according to 2016 IEEE +, you are able to divide these complex problems into
spectrum Top Programming Language ranking. smaller sets by creating objects.

Learning C++ is a wise investment for all programmers. Power of standard library (Standard template library - STL)
- The power of C++ extends with the use of standard
“C++ is a statically-typed, free-form, (usually) compiled, libraries contained in it. These libraries contain efficient
multi-paradigm, intermediate- level general-purpose algorithms that you use extensively while coding. This
middle-level programming language.” saves ample amount of programming effort, which
otherwise would have been wasted reinventing the wheel.
In simple terms, C++ is a sophisticated, efficient and a
general-purpose programming language based on C. II. Anatomy of a C++ program
While Bjarne Stroustrup was working in AT&T Bell Labs in Your first C++ program
1979, he faced difficulties in analyzing UNIX kernel for 1. #include <iostream>
distributed systems. The current languages were either too 2. using namespace std;
slow or too low level. So, he set forward to create a new 3. int main()
language. His aim was to create a language with far higher 4. {
level of abstraction while retaining the efficiency of C. 5. cout << "Hello World";
This new programming language was named C with 6. return 0;
Classes, but was later renamed to C++ (++ refers to the 7. }
increment operator in C).
Code Discussion
III. Five Basic Concepts of C++ Line 1. #include <iostream>
1. C++ Variables - The backbone of any programming The standard I/O system is declared in the header file:-
language. A variable is merely a way to store some <iostream> iostream is a header file which provides us with
information for later use. input & output streams. Header files contained
predeclared function libraries, which can be used by users
2. C++ Control Structures - The code is read by the for their ease Line
compiler line by line (from top to bottom, and for the most
part left to right). This is known as "code flow." When the 2. using namespace std;
code is being read from top to bottom, it may encounter a Namespaces were introduced into C++ to resolve identifier
point where it needs to make a decision. Based on the name conflicts
decision, the program may jump to a different part of the Namespace collects identifiers used for class, object and
code. variables.
This ensured that two objects can have the same name and I. Decision Making in C++
yet be treated differently if they belonged to different Decision making statements in programming languages
namespaces. decides the direction of flow of program
execution. Decision making statements available in C or C+
Line 3. int main() + are [1].
-The actual program starts with the function named main().
-When your program starts, main() is called automatically. 1. if statement
main(), is the function which holds the executing part of 2. if..else statements
program its return type is int. 3. nested if statements
main() function is the body of your program. All processing 4. if-else-if ladder
should be done in this part. 5. switch statements
6. Jump Statements:
Line 4 and 7: { } a. break
The open brace ( { ) at line 4 indicates the beginning of b. continue
main's function definition, and the closing brace ( } ) at line c. goto
7, indicates its end. Everything between these braces is the d. return
function's body that defines what happens when main is
called. All functions use braces to indicate the beginning In C++, switch, case, break, and default are reserved words.
and end of their definitions. In a switch structure, first the expression is evaluated. The
When writing a function, or a class, or an if statement, or a value of the expression is then used to perform the actions
loop, C++ uses an opening curly brace to begin the body of specified in the statements that follow the reserved word
the function, class, if/else statement, or loop. case. Recall that in a syntax, shading indicates an optional
Then you put all the normal statements and close it all with part of the definition. Although it need not be, the
a matching closing curly brace. expression is usually an identifier. Whether it is an
identifier or an expression, the value can be only integral.
Line 5: cout << “Hello World”; The expression is sometimes called the selector. Its
cout is use to display something on the monitor. value determines which statement is selected for
<< output redirection operator. execution. A particular case value should appear only once.
Whatever follows the output redirection operator is One or more statements may follow a case label, so you do
written to the console. not need to use braces to turn multiple statements into a
if you want a string of characters written, be certain to single compound statement. The break statement may
enclose them in double quotes (") or may not appear after each statement.

Line 6: return 0; VIII. Jump Statements


Like all functions, must state what kind of value it returns. 1. break statement - used to terminate the loop in which it
It returns the integer value 0. is used. Syntax for break is break; The break statement is
A value may be returned to the operating system to used to terminate the loop or statement in which it
indicate success or failure, or using a failure code to present. After that, the control will pass to the statements
describe a cause of failure. that present after the break statement, if available. If the
break statement present in the nested loop, then it
III. Things to Remember in Creating C++ Program terminates only those loops which contains break
Some words are reserved by C++, and you may not use statement.
them as variable names. These are keywords used by the
compiler to control your program. Keywords include if, 2. continue statement - used to skip over the execution
while, for, and main. part of the loop on a certain condition. Continue statement
Most of syntax in C++ are written on lower case letters. transfers the control to the beginning of the loop. Basically,
Semicolon ( ; ) is very special and important. . Don’t forget it skips its following statements and continues with the
to include this on the every last line of the code. Ex: cout next iteration of the loop.
<< “hello”;
Syntax for continue is continue;
C++ Flow Control
3. goto statement - used to transfer control to the labeled
Introduction statement in the program. The label is the valid identifier
There come situations in real life when we need to make and placed just before the statement from where the
some decisions and based on these decisions, we decide control is transferred. Syntax for goto is goto label;
what we should do next. Similar situations arise in
programming also where we need to make some decisions
and based on these decisions we will execute the next
block of code.

You might also like