Syntax in C++

Syntax in C++

Syntax in C++ can be defined as a collection of objects that communicate via invoking other’s methods.

C++ Program

#include <iostream>
using namespace std;

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

Output

Hello World

#include<iostream>

It is a header file that works with input and output objects, such as cout. It tells the compiler to include the standard iostream file which contains declarations of all the standard input/output library functions.

 

using namespace std

using namespace std is used to import the std namespace into the current namespace of the program. It means the use of names for objects and variables from the standard library.

int main()

int main() is used to declare a function named “main” and it  returns data of integer type. Execution of every C++ program starts with the main() function. Every C++ program have a main() function.

{ and }

The opening braces ‘{‘ shows that starting of the main function and the closing braces ‘}’ shows the ending of the main function. Everything between two braces the body of the main function.

cout<<“Hello World”;

This line displays the message “Hello World” on the screen. A semi-colon ‘;’ is used to end a statement. Everything followed by the character “<<” is displayed to the output device and The cout is a predefined object of ostream class. 

return 0;

Return is also a statement. This statement is used to return a value from a function. It terminates the main( ) function and causes it to return the value 0 to the calling process

 

Read more, Data types in C

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *