How to Explain C++ in brief
Print Friendly, PDF & Email

In C++, the keyword (++) is actually an increment operator and is used in many programming languages which means increment by one. Interesting? Well, then why not learn more about it? Here you go…

C++ language gets its origin from C languageC++ can be denoted as follows:

C= C+1 ; which means,

If c= mother,

Then c++=child

As we all know that child always inherit features from her mother and develop their new features as well. So, we can say that c and c++ are not distinct languages and c++ has features of c and has its own features. If we want to get success in life, we must stick to our roots in the same way c++ is most popular language because its root is c language.

Dr. Bjarne Stroustrup at AT & T’s Bell labs added additional features to the C Language in 1980 and developed a new language called C++.

Let us take an example of Aquatic animals (animals live in water) e.g. fish, octopus

Aquatic Animals (class)

Fish, octopus (objects)

So, we can say that a Class is a set of similar kind of objects and object is an instance of class or object is an identifiable unit having some behavior and distinctiveness. C++ is an object based Programming language.

C++ uses some powerful features like:

  • Polymorphism
  • Inheritance
  • Encapsulation

OOPs Features

Some influential features of OOPs (Object Oriented programming language) are:

  1. Based on the data
  2. Programs are made by using objects which represent real-world objects.
  3. Both function and data are encapsulated.
  4. Protection of data is done by using Data hiding.
  5. New data and function can be added easily.
  6. One object communicates with other by using the function.
  7. The bottom-up approach is used during program design.

C++ character sets

Character set in c++ is the building block to form some basic program elements for instance identifier, variables, array etc.

Letters: Lowercase letters a-z, Uppercase letters A-Z

Digits: 0-9

Special characters like | { ^ % } – { [ ] & _ . ?~: ‘‘(blank) / \* + “= < # (

These special characters are used at different locations according to requirement.

Keywords

These are reserved words which have some predefined meaning to the compiler. Some commonly used keywords are

void register typedef Char float
Long While If struct break
else short const for Size of
return do switch case extern
double continue goto static auto

Variables

The memory of the computer is divided into small blocks of space. These blocks are large enough to hold an instance of some type of data. These blocks of space are called memory location.

Variable is actually a name given to its memory location so that the user does not require to remember the address of the location.

Variable have characters. The variable name should be unique within a program. To declare a variable, one must provide the following:

  1. name
  2. type
  3. value

Naming variables

  1. A variable name can short as a single letter.
  2. The variable name must begin with the letter of the alphabet or underscore (_).
  3. After specifying the first letter or underscore it can contain numbers, letters, and additional underscore.
  4. Reserved words should not be used as reserved words.
  5. Black spaces are not allowed between variables names.

e.g. roll_no = valid

Salary=valid

aug98_score = valid

Count=invalid (reserved word)

Your Age = invalid (no space is allowed)

78aug_score=invalid (first letter must be alphabet)

Compiler interprets uppercase and lowercase letter differently so take care of that e.g. sales, Sales, saLes, SALES these all variables are different.

In c, you can declare variables in the beginning of the block of code, but in C++ you can declare it anywhere.

Constants

These are data values that never change their values during program execution. C++ provides 4 types of constant:

  1. Integer constants = Whole Number without any fractional part.
  2. Floating point constant = Real number that has fractional part these are written in one of the two forms fractional form or Exponent form
  3. Character constant = Contain one or more character enclosed in single quotes.
  4. String constant = Contain number of character enclosed in double quotes, string constant is automatically added with null character “\0”.

Input/output (I/O) in C++

In C++ cin and cout objects are used for input and output.

The cout object sends data to the standard output device. Format of cout is something different from that of regular C++ commands

Cout<<data [<<data]

Here, data can be constant, variable, expressions or combination of all three. Operator << is used redirecting output to screen and called bitwise shift operator or put to the operator. The header file iostream.h is used for bitwise shift operator.

You can use cin operator to get input from the keyboard. The header file iostream.h is used for cin operator. Format of cin operator is as follows

Cin[>>value];

Example :

int N;

char ch;

cout<<”Enter any number”;

cin>>N;

cout<<”Enter your choice”;

cin>>ch;

Escape Sequence

Escape Sequences in C++ are used to display special characters in a string. These characters are not displayed in the output. Escape Sequences in C++ are used to modify the string.

E.g.

Escape sequences Meaning
\’ Single Quote
\” Double Quotes
\? Question Mark
\n New Line
\t Horizontal Tab
\v Vertical Tab
\a Alarm
\b Backspace
\f New page

Basic structure of C++ Program

C++ program is constructed in the following manner:

Header Section

Contain name,author,revision number

Include Section

  • Contain #include statement
  • Constant and type section
  • Global variable section
  • Function section
  • User defined functions
  • main() section

If the program is structured in above format then it has following advantage

  • easy to read
  • easy to modify
  • easy to format

Skeleton outline of simple c++ Program

#include < iostream.h> (Preprocessor directive goes here)

Int main()

{

< —-Block ———-Program goes here

}
Here main() function is the point where all c++ programs start their execution. Its content always executed first whether it is in the beginning, middle, or end of the code.main followed by ()(Parenthesis) that optionally can include arguments within them.

return 0;

return instruction finishes the main function and return the code that the instruction is followed by in this case it is it is 0.

Concluding Words

Once you have good experience with a lower level language, you will have a better understanding of how higher-level platforms work. Over the long term, this will help make you a better developer in C#, Java etc. And, it can be helpful in web application development.

I hope my article helps in understanding basic concepts of C++.  In case of any other queries, you can surely post your valuable comments in the comments section below…

  •  
  •  
  •  
  •  
  •  

LEAVE A REPLY

Please enter your comment!
Please enter your name here