Introduction to C++

Dennis Ritchie of Bell Labs created the C Programming Language in 1971-1972 as he, along with Ken Thompson worked together to design the UNIX operating system. C++ was developed later by Bjarne Stroustrup at Bell Labs during 1983-1985. In the 90s, C++ dominated the programming world and nearly every application software used this fundamental language. Now it is used in many different forms and other languages have been derived from c++.

C++, as the name may suggest you, is an extension of C. The term C++ was first used in 1983. All programs typed in C can be typed in C++ with some few changes. C++ consists of something called as "Object Oriented Programming" (we will discuss this in later chapters), which enables the programmer to build large programs with ease and convenience.

Comments are typed within /*....*/ , if the comments are multi-lined or if they are single-lined, then after two slashes, i.e. // and the comment ends when the line ends. Comments can be placed anywhere in the program. They are ignored by the compiler.

Basic structure of C++ program

Given below is the example of a basic c++ program. Do not worry about any of these things in detail as we will be going through each of these elements in the coming chapters. Just have a look!

As you can see above, any C++ program consists of a header file and a main function. It is important to note the order in which the statements are written.

Sample program in C++

Given below is an example of a program that prints a string (series of characters). Again do not worry about the program or the syntax as that will be explained in later chapters. Just go through the structure of writing the code in C++.

In the above program, iostream.h is a header file, which contains declaration for many input and output operations. Here "cin" is used for input and "cout" is used for output. Both of them are defined in "iostream.h". There are many such header files like math.h, string.h, stdlib.h, ctype.h, etc. They shall be discussed whenever they are included in the program.

Keywords and Identifiers:

A program can be treated as collection of words. These words can be classified into two categories namely, keywords and identifiers.

Keywords:

These words are already defined in C++ and are used only for their intended purposes. They are case-sensitive. For e.g.: int, void, for, do, while, if, else, etc.

Identifiers:

They are used to represent a variable name, constant name or a function name. To form an identifier, one can use English alphabets (capital or small), numbers or underscore (_). For e.g.: value_weight, calculateCarSpeed, etc.
Remember:
1. Any identifier must not start with a number.
2. A keyword should never be used as an identifier.

About Us!

'Z Series Innovations' is an e-learning solution for learning all technical stuff online. It is an online portal that gives an enhanced way of learning and guidance in various fields of engineering which include robotics, electronics, communication,computer science, embedded systems and its real life applications.

Join Us

Do you feel like contributing to this website technically? Jump in!

Your technical expertise would be needed to create quality articles and content on this site and hence contribute to this growing global community of technical enthusiast.