endl is a function not a keyword.
#include <iostream>
int main()
{
std::cout<<"Hello World"<<std::endl; //endl is a function without parenthesis.
return 0;
}
To understand the picture of endl you firstly need to understand about "Pointer to Functions" topic.
look at this code (in C)
#include <stdio.h>
int add(int, int);
int main()
{
int (*p)(int, int); /*p is a pointer variable which can store the address
of a function whose return type is int and which can take 2 int.*/
int x;
p=add; //Here add is a function without parenthesis.
x=p(90, 10); /*if G is a variable and Address of G is assigned to p then
*p=10 means 10 is assigned to that which p points to, means G=10
similarly x=p(90, 10); this instruction simply says that p points to add
function then arguments of p becomes arguments of add i.e add(90, 10)
then add function is called and sum is computed.*/
printf("Sum is %d", x);
return 0;
}
int add(int p, int q)
{
int r;
r=p+q;
return r;
}
Compile this code and see the Output.
Back to topic...
#include <iostream>
//using namespace std;
int main()
{
std::cout<<"Hello World"<<std::endl;
return 0;
}
iostream file is included in this program because the prototype of cout object is present in iostream file and std is a namespace. It is used because defination(library files) of cout and endl is present in namespace std;
Or you can also use "using namespace std" at top, so you don't have to write "std::coutn<<....." before each cout or endl.
when you write endl without paranthesis then you give the address of function endl to cout then endl function is called and line is changed.
The reason Behind this is
namespace endl
{
printf("\n");
}
Conclusion: Behind C++, code of C is working.