Header Ads

Basic concept of C++

What is C++?
C++ is a general-purpose programming language.
C++ is used to create computer programs. Anything from art applications, music players and Video games.

 First C++ program
Below is a simple code that "Hello world" as an output.

#include <iostream>

using namespace std;

int main()
{
    cout << "Hello world!";
    return 0;
}












Now lets break down the parts of the code.
The first line of the code
#include <iostream>
C++ offers various headers, each of which contains information needed for programs to work properly. This particular program calls for header <iostream>. The pound sign (#) at the beginning of a line targets the compiler's pre-processor. In this case, #include tells the pre-processors to include the <iostream> header.



  •  The <iostream> header defines the standard stream object that input and output data.
  • In our code, the line using namespace std; tells the compiler to use the std (standard) namespace.
  • The curly brackets {} indicate the beginning and end of a function, which can also be called the function's body. The code in the brackets indicates what the function does when executed
  • The next line     cout << "Hello world!";, is responsible for the display of "Hello world!". In most program environments, the standard default output destination is the screen. In C++, cout is the stream object used to access the output destination. Cout is used in combination with the insertion operator. write the insertion operator as << to insert the data that comes after it into the stream that come before. The semicolon is used to terminate a statement.
  • The last instruction in the program is the return statement. The line  return 0; terminatte the main() function and causes it to return the value 0 to the calling process. 




No comments