Welcome to C++

0 0
Read Time:1 Minute, 52 Second

Welcome to C++

C++ is a popular cross-platform language that can be used to create high-performance applications – operating systems, browsers, video-games, art applications and so on.

C++ was derived from C, and is largely based on it.

A C++ program is a collection of commands or statements.

Below is a simple program template.

#include <iostream>
using namespace std;

int main()
{

  return 0;
};

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.

Hello World Program in C++

Let’s output “Hello world!” to the screen!
To do that, we will add cout<<“Hello world!”line to our main() function body:

#include <iostream>
using namespace std;

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

cout is used to perform output on the standard output device which is usually the display screen.
cout is used in combination with the stream insertion operator <<.
Note: that you can add multiple insertion operators after cout.

In C++, the semicolon is used to terminate a statement. Each statement must end with a semicolon. It indicates the end of one logical expression.

Headers

C++ has headers, each of which contains information needed for programs to work properly.
We have already seen the standard <iostream> header on our first C++ program:

#include <iostream>
using namespace std;

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

#include pre-processor is used for adding a standard or user-defined header files to the program.

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

Namespaces

namespace is a declarative region that provides a scope to the identifiers (names of elements) inside it.
In our code, the line using namespace std; tells the compiler to use the std (standard) namespace:

#include <iostream>
using namespace std;

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

The std namespace includes features of the C++ Standard Library.

Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

Leave a Comment