This is a part of a c++ program:

cout<< "Width:" << Width << "\n";
cout << "Length: " << Length << endl;

what does the "\n" do in oppose to endl; ?

also,
when do you use void main instead of int main at the beginning of the program?

>what does the "\n" do in oppose to endl; ?
endl forces the stream to be flushed, which means that the characters will be written immediately. "\n" doesn't flush the stream, so it's possible that if something happens to interrupt the program between the time you write the characters and the time the stream is flushed, you'll lose the output.

Generally you don't have to worry about using endl because the stream will be flushed at reasonable times for cout, or you should be using cerr for unbuffered output.

>when do you use void main instead of int main at the beginning of the program?
Never. Anyone who does it is wrong.

int main()
{
   // code here
}

int main() is standard while void main() is not standard. It is good habit to use int main() instead of void main().

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.