Wednesday, February 7, 2018

C++ Basic Syntax

C++ Basic Syntax


  1. includes the standard input output library functions. It provides cin and cout methods for reading from input and writing to output respectively.
  2. The line using namespace std; tells the compiler to use the std namespace. Namespaces are a relatively recent addition to C++.
  3. The line int main() is the main function where program execution begins.
  4. The next line cout << "Welcome to Programming Tutorials by Abhishek"; causes the message "Welcome to Programming Tutorials by Abhishek" to be displayed on the screen.
  5. Each statement must be end with semi colon (;).
  6. The next line return 0; terminates main( )function and causes it to return the value 0 to the calling process.

#include <iostream>
using namespace std;
int main() {
   cout << "Welcome to Programming Tutorials by Abhishek";
   return 0;
} 

  • To execute the above code you have to install GNU C/C++ Compiler. Otherwise you can use IDE like Codeblocks.
  • Simply copy the above code and paste it in codeblocks and click on build and run then it will display the output in the command prompt.

Standard end line (endl)

  1. The endl is a predefined object of ostream class. It is used to insert a new line characters and flushes the stream.
  2. By default the output will be displayed side by side only which means in a single line.
  3. But if you want to display output from a new line you have to use endl .

No comments:

Post a Comment