Articles added in Mathematics Lab | Cyber Lab is now open | Astronomy Lab is now open | VLSI Lab is now open | 120 SEO Tips article published | More exciting articles coming soon!

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.

note 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!

note 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++.

note 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.
  1. Keywords:
  2. 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.

  3. Identifiers:
  4. 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.

1. Any identifier must not start with a number.
2. A keyword should never be used as an identifier.

CACKLE comment system

Programming Resources
Computer Networking Fundamentals Android Application