History of C++
C++ is an object oriented programming language. It is a combination of C language and Simula67 language. Because C is having power features and simula67 is having basics of class. C++ was introduced by Bjarne Stroustrup in the year 1980 at AT & T (American Telephony and Telegraphy) bell labs, Murry hill, New Jersy, USA. At that time the name C with classes. After that they changed the name in 1983 c with classes to C++.
Applications of C++
C++ CharacterSet
Variable
It’s a memory allocation which enable you to store the data temporarily during the program execution. In other words a space to store the data. An identifier is nothing but user defined names.
Syntax:datatype variablename;
C++ data types
It represents the type of value to be presented or stored in the variables. All the data types of C language is legal in C++. There are 3 types.
1. Built in Datatypes
2. User-defined Datatypes
3. Derived Datatypes
Built-in Datatypes:-
These are 3 types.
Integral datatypes
Floating point datatypes
void
Integral Data types:-
integer, character
Integer short form is int.
Character short form is char.
Int occupies 2 bytes space in the memory. Range is -32,768 to 32,767.
unsigned int accepts only positive values. Range is 0 to 65,535.
Long int occupies 4 bytes space in the memory. Range is -2,147,483,648 to 2,147,483,647.
Unsigned long int range is 0 to 4,294,967,295.
Character short form char. It occupies 1 byte space in the memory.
Unsigned char Range is 0 to 255.
Signed char Range is -128 to 127.
Floating
Void:- occupies 0 bytes.
User defined Data types:-
User defined data types are class, structure, enumeration, union.
Derived Data types:- Derived data types are pointer, array, function.
Tokens
Smallest individual word is nothing but token. Tokens are 5 types:
1. Keywords
2. Identifiers
3. String
4. Constants
5. Operators
Key Words:- Keywords are nothing but reserved words. The meaning of those words is already defined to the compiler for the particular purpose. We can’t change the meaning of the keyword. But we can apply the functionality of the keyword to any name. There are 48 keywords in c++. In that 32 are C keywords and 16 are additional. Keywords should not be used as identifiers.
Identifiers:- Identifiers means any name except keywords.
Ex:- variable names, function names, label names, string names, array names, etc.
String:- String is nothing but character array. String is a collection of character.
Syntax:- datatype variablename[size]; Constants:-we can make any variable as a constant. And we can use literal constants in c++. Literal constants means making string constants are identifying the integer constants. Through enum it is possible.
syntax:- const datatype variablename; is used for making the single variable constant.
Dealing with input and output functions with c++
cout(console out):- cout is an object of ostream class. which is used to perform the output operation. The cout works exactly similar with printf function in the C-language. The cout will supports an operator called insertion or put to operator(“<<”). As per programming requirements we can use escape sequences but does not supports to work with format specifiers. Cin(consloe in):- It is an object of istream class which enable you to extract the value from the input device and assign to the specified variable. It will works almost similar to the scanf function in c-language. The cin object will supports an operator called extraction (or)get from operator(“>>”)
NOTE: Using multiple insertion(<<) with the respective of cout are using multiple extraction operator (>>) with the respective of cin is known as cascading. The cin is an object of istream class. The cout is an object of ostream class. Both istream and ostream classes are existed in the iostream.h header file.
Why to use void as a return type?
As we know that function means which returns a value. If you feel to write void as a return type at the time of compilation you are getting a warning “Function should return a value”.
Every Function will return int type bytes to operating system implicitly to kill the nature of returning we need to write void as return type. (void means “0” bytes data type)When you are not interested to write void as return type, recommended to write “return 0” at the end of the program.
//sample program
#include < iostream.h >
#include < conio.h >
void main()
{
clrscr();
cout<<“Welcome to C++”;
getch();
}
How to save the program:-
press functional key F2.
Then type the filename.cpp
Ex:- D:\1.cpp enter
How to compile the program?
Alt+C- enter - Compile enter
How to Execute the program?
Alt+R - Enter - Execute
How to see the output?
Alt+F5 - Output
C++ is an object oriented programming language. It is a combination of C language and Simula67 language. Because C is having power features and simula67 is having basics of class. C++ was introduced by Bjarne Stroustrup in the year 1980 at AT & T (American Telephony and Telegraphy) bell labs, Murry hill, New Jersy, USA. At that time the name C with classes. After that they changed the name in 1983 c with classes to C++.
Applications of C++
- C++ is a Superset to C language. Because all C programs run under C++. But C++ programs cannot run under C. So C is a Subset.
- C++ is a free form language.
- C++ is a robust language. Because it is having rich set of operators, built in functions, keywords etc.
C++ CharacterSet
- The c++ character set is ASCII character Set
- Alphabets - A to Z(65 to 90) a to z(97 to 122)
- Numbers - 0 to 9(48 to 57)
- Symbols - All Keyboard Symbols
- Space 32
- Enter 13
- Esc 27
- etc
Variable
It’s a memory allocation which enable you to store the data temporarily during the program execution. In other words a space to store the data. An identifier is nothing but user defined names.
Syntax:datatype variablename;
C++ data types
It represents the type of value to be presented or stored in the variables. All the data types of C language is legal in C++. There are 3 types.
1. Built in Datatypes
2. User-defined Datatypes
3. Derived Datatypes
Built-in Datatypes:-
These are 3 types.
Integral datatypes
Floating point datatypes
void
Integral Data types:-
integer, character
Integer short form is int.
Character short form is char.
Int occupies 2 bytes space in the memory. Range is -32,768 to 32,767.
unsigned int accepts only positive values. Range is 0 to 65,535.
Long int occupies 4 bytes space in the memory. Range is -2,147,483,648 to 2,147,483,647.
Unsigned long int range is 0 to 4,294,967,295.
Character short form char. It occupies 1 byte space in the memory.
Unsigned char Range is 0 to 255.
Signed char Range is -128 to 127.
Floating
Void:- occupies 0 bytes.
User defined Data types:-
User defined data types are class, structure, enumeration, union.
Derived Data types:- Derived data types are pointer, array, function.
Tokens
Smallest individual word is nothing but token. Tokens are 5 types:
1. Keywords
2. Identifiers
3. String
4. Constants
5. Operators
Key Words:- Keywords are nothing but reserved words. The meaning of those words is already defined to the compiler for the particular purpose. We can’t change the meaning of the keyword. But we can apply the functionality of the keyword to any name. There are 48 keywords in c++. In that 32 are C keywords and 16 are additional. Keywords should not be used as identifiers.
auto | break | case | char |
const | continue | default | do |
Double | Else | enum | extern |
float | for | goto | if |
int | long | register | return |
short | signed | sizeof | static |
struct | switch | typedef | union |
unsigned | Void | volatile | while |
asm | new | delete | operator |
template | private | public | protected |
friend | virtual | this | try |
throw | inline | catch | class |
Identifiers:- Identifiers means any name except keywords.
Ex:- variable names, function names, label names, string names, array names, etc.
String:- String is nothing but character array. String is a collection of character.
Syntax:- datatype variablename[size]; Constants:-we can make any variable as a constant. And we can use literal constants in c++. Literal constants means making string constants are identifying the integer constants. Through enum it is possible.
syntax:- const datatype variablename; is used for making the single variable constant.
Dealing with input and output functions with c++
cout(console out):- cout is an object of ostream class. which is used to perform the output operation. The cout works exactly similar with printf function in the C-language. The cout will supports an operator called insertion or put to operator(“<<”). As per programming requirements we can use escape sequences but does not supports to work with format specifiers. Cin(consloe in):- It is an object of istream class which enable you to extract the value from the input device and assign to the specified variable. It will works almost similar to the scanf function in c-language. The cin object will supports an operator called extraction (or)get from operator(“>>”)
NOTE: Using multiple insertion(<<) with the respective of cout are using multiple extraction operator (>>) with the respective of cin is known as cascading. The cin is an object of istream class. The cout is an object of ostream class. Both istream and ostream classes are existed in the iostream.h header file.
Why to use void as a return type?
As we know that function means which returns a value. If you feel to write void as a return type at the time of compilation you are getting a warning “Function should return a value”.
Every Function will return int type bytes to operating system implicitly to kill the nature of returning we need to write void as return type. (void means “0” bytes data type)When you are not interested to write void as return type, recommended to write “return 0” at the end of the program.
//sample program
#include < iostream.h >
#include < conio.h >
void main()
{
clrscr();
cout<<“Welcome to C++”;
getch();
}
How to save the program:-
press functional key F2.
Then type the filename.cpp
Ex:- D:\1.cpp enter
How to compile the program?
Alt+C- enter - Compile enter
How to Execute the program?
Alt+R - Enter - Execute
How to see the output?
Alt+F5 - Output