0

What's the difference between : {cout << x*2 ;} and {return x*2;} in a function?

functions

15th Feb 2017, 6:51 AM
mohammad mazhariroshan
mohammad mazhariroshan - avatar
2 Answers
+ 1
cout << x * 2; will put the result of x * 2 into the output stream and print it (usually to the console/terminal window). Example where x = 5: cout << x * 2; // prints 10 in the console Where return x * 2; will return the result of x * 2 to the function call. example: int getNumber(int x) { return x * 2; } int y = getNumber(10); // y = 20
15th Feb 2017, 7:02 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
thank u 🙂👍
15th Feb 2017, 7:04 AM
mohammad mazhariroshan
mohammad mazhariroshan - avatar