C++ Basic Syntax
- includes the standard input output library functions. It provides cin and cout methods for reading from input and writing to output respectively.
- The line using namespace std; tells the compiler to use the std namespace. Namespaces are a relatively recent addition to C++.
- The line int main() is the main function where program execution begins.
- 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.
- Each statement must be end with semi colon (;).
- 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)
- The endl is a predefined object of ostream class. It is used to insert a new line characters and flushes the stream.
- By default the output will be displayed side by side only which means in a single line.
- But if you want to display output from a new line you have to use endl .
No comments:
Post a Comment