+ 1
In c++ When we write ; and when de write <<endl;
I am a begginer in c++ Example 1 Cout>>"hello"; Example 2 Cout>>"hello">>endl; Please tell me when we write as the example 1 and when we write as the example 2 Or it is the same Thank you.
5 Answers
+ 2
example 2 are used when the next output needs tobe in the new line.
example 1 used when the next output need to be in the same line
+ 3
The deference between
Example1
cout<<"hello;
And
Example2
cout<<"hello"<<endl;
Is in the 1st ex you are saying to the program write hello and stop
But in the other ex you are saying to the program write hello and return to a new line and stop
endl = "\n"
Its the same the only deference between them is :
endl used outside the " "
cout<<"hello"<<endl;
"\n" used inside the " "
Cout<<"hello\n";
More examples:
Ex1
cout<<"hello "<<"world";
Output
hello world
Ex2
Cout<<"hello"<<endl<<"world";
Output
hello
World
Ex3
Cout<<"hello"<<"world"<<endl<<"i am code";
Output
Hello world
I am coder
Hope this will help you đđđ
And if you have any other questions i am here bro
+ 1
~ swim ~
Thank you i just missed it
0
Thank you Taste