C++ syntax:
Lets learn the code:
#include<iostream>
using namespace std;
int main()
{
cout<<"Hello world"<<endl;
return 0;
}
In this above code,
In Line 1: #include<iostream> it is a library, it can work with input and output files. If we does not write this library then we see a syntax error because with the help of this we can give output and input.
In Line 2: using namespace std, it is used for scope of a function. and we can use names of objects and variables.
In Line 3: int main() , is the starting of a program , everything we write in main() means it will execute. and int is a data type. The Datatypes int, float, double, char, long double all return something. But a datatype void does not return anything.
In Line 4: cout<<"Hello World">>; it means it will execute and print Hello World. Cout means it will display the information.
In Line 5: return 0; it means return type is int and int is a datatype that will return something so it returns 0.
Note: Every C++ statement ends with a semicolon. and blank spaces will be ignored.
It is a basic syntax for C++ .
Table example:
#include<iostream>
using namespace std;
int main()
{
cout<<"Table of 3"<<endl;
cout<<"-----------"<<endl;
cout<<"3*1="<<3*1<<endl;
cout<<"3*2="<<3*2<<endl;
cout<<"3*3="<<3*3<<endl;
cout<<"3*4="<<3*4<<endl;
cout<<"3*5="<<3*5<<endl;
cout<<"3*6="<<3*6<<endl;
cout<<"3*7="<<3*7<<endl;
cout<<"3*8="<<3*8<<endl;
cout<<"3*9="<<3*9<<endl;
cout<<"3*10="<<3*10<<endl;
}
No comments:
Post a Comment