Reputation: 101
For example,
Would it be more memory efficient to display these variables like this:
std::cout << "First char is " << char1 << " and second char is " << char2;
rather than this:
std::cout << "First char is " << char1;
std::cout << " and second char is " << char2;
Of course, I'm not literally worried about two lines of code.. But I'm trying to learn to write code more efficiently
Thank you
Upvotes: 5
Views: 528
Reputation: 53047
Having it be a single statement could theoretically be faster as the compiler can rearrange the order of argument evaluation more freely. However, this is talking about 0.00000000000001% difference and is pointless. Don't care about this - the bottleneck is in the console itself.
Anyway, column alignment is really helpful for readability and so try this:
std::cout << "First char is " << char1;
std::cout << " and second char is " << char2;
Or this:
std::cout << "First char is " << char1
<< " and second char is " << char2;
(I prefer the first because I find it easier to format in my text editor).
Upvotes: 3
Reputation: 9040
It makes no difference with programs that small. The toss-up comes with readability. Do u want it quick and easy or more readable?
Upvotes: 0