Introduction to C++

C++ is a statically typed,general purpose programming language. C++ was derived C, band is largely based on it.

Note: A programming language is said to used static typing when type checking is performed during compile-time as opposed to run time.

Standard Libraries

Standard C++ has three important components

  • Core language
    Provides all necessary building blocks, including variables, data types, literals, etc.
  • Standard library
    Offers a rich set of functions for manipulating files, string, etc.
  • Standard template library
    Offers methods for the manipulation of data structures, etc.

First program of C++:-

Write a program in C++ print a massage on output screen.

#include<iostream.h>
using namespace std;
int main()
{
    cout <<"Hello world";
    return();
}

Program Explanation

  • Pound sign(#)
    The pound sign(#) at the beginning of a line targets the compiler's pre-processor to include the <iostream.h> header.

      #include<iostream.h>
    

C++ offers verious headers, each of which contains information need for programs to work properly. This particular program calls for the header file <iostream.h>.

The <iostream.h> header define the standard stream objects that input and output data.

  • using namespace std;
    In our code, the line using namespace std; tells the compiler to use the std (standard) namespace. The std namespace includes features of the C++ standard library.

  • main() function
    Program execution begins with the main() function. The entry point of every C++ program is main() function.

  • Curly brackets {}
    Curly brackets {} indicate the beginning and end of a function, which can also be called the function's body. The information inside the brackets indicates what the function does when executed.

  • cout<< "Hello world";
    cout<< "Hello world"; results in the display of Hello world to output screen.

  • cout : is used in combination with the insertion operator

  • Insertion operator << : Write the insertion operator as << to insert the data comes after cout into the stream the comes before.

  • Semicolon (;)
    The semicolon (;) is used to terminate a statement.

  • return 0;
    The last instruction in the program is the return statement. The line return 0; terminate the main() function and causes it to return value 0 to the calling process.


You've successfully subscribed to Developer Insider
Great! Next, complete checkout for full access to Developer Insider
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.