UNIT I
A ) Introduction to C++
C++ is a multi-paradigm programming language that supports object-oriented
programming (OOP), created by Bjarne Stroustrup in 1983 at Bell Labs, C++
is an extension(superset) of C programming and the programs are written in C
language can run in C++ compilers.
C++ is regarded as a middle-level language, as it comprises a combination of
both high-level and low-level language features.
originally named C with Classes but later it was renamed C++ in 1983.
C++ is a superset of C, and that virtually any legal C program is a legal C++
program.
C++ is used by programmers to create computer software. It is used to create
general systems software, drivers for various computer devices, software for
servers and software for specific applications and also widely used in the
creation of video games.
C++ is used by many programmers of different types and coming from
different fields. C++ is mostly used to write device driver programs, system
software, and applications that depend on direct hardware manipulation under
real-time constraints.
C++ compilers
Borland C++
Turbo C++
Microsoft Visual C++
Zortech C++
UNIX C++ (AT&T)
GNU Compiler
Collection (GCC)
, B) C++ TOKENS
Token-- Each individual word and punctuation is referred to as a token in C++.
Tokens are the smallest building block or smallest unit of a C++ program.
These following tokens are available in C++:
● Identifiers
● Keywords
● Constants
● Operators
● Strings
1) Identifiers are names given to different entries such as variables, structures, and
functions.
Also, identifier names should have to be unique because these entities are used in the
execution of the program.
A C++ identifier is a name used to identify a variable, function, class, or any other
user-defined item.
a) An identifier starts with a letter A to Z or a to z or an underscore (_) followed by
zero or more letters, underscores, and digits (0 to 9).
b) C++ does not allow punctuation characters such as @, $, and % within identifiers.
c) C++ is a case-sensitive programming language. Thus, Manpower
and manpower are two different identifiers in C++.
Here are some examples of valid identifiers names −
abc a_123 _temp j a23b9 retVal
2) Keywords are reserved words which have fixed meaning and its meaning cannot
be changed. The meaning and working of these keywords are already known to the
compiler. C++ has more numbers of keyword than C and those extra ones have special
working capabilities.
,The following list shows the reserved words in C++. These reserved words may not be
used as constant or variable or any other identifier names
else new this
auto ------ operator throw
bool ------ private true
break export protected try
case extern public typedef
catch false register typeid
char float -------- typename
class for return union
const friend short unsigned
goto signed using
continue If sizeof virtual
default Inline static void
delete Int static_cast volatile
, do Long struct char
double mutable switch while
dynamic_cast namespace template
3) Constants
Constants are like a variable, except that their value never changes during execution
once defined.
● 4) Operators
C++ operator is a symbol that is used to perform mathematical or logical
manipulations. Dicussed later
C) C++ P rogram Structure
Let us look at a simple code that would print the words Hello World.
#include <iostream>
using namespace std;
// main() is where program execution begins.
int main() {
cout << "Hello World"; // prints Hello World
return 0;
}
Let us look at the various parts of the above program −