So in this instance I'm confused. We're voiding the int x but then in the last part we say int main and our output is x. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

So in this instance I'm confused. We're voiding the int x but then in the last part we say int main and our output is x.

#include <iostream> using namespace std; void printSomething(int x) { cout << x; } int main() { printSomething(42); } I'm in need of clarification because I think we're voiding the int but then we bring it back and get 42. I'm just confused on what is happening here

11th Apr 2018, 2:47 AM
Sir
1 Answer
+ 2
When you use void, you’re saying that the method does not return anything (you’re not returning x, just printing.) Cout is used to print text to the console. Printing text and returning a value are not the same. Returning a value does not automatically print it.
11th Apr 2018, 4:19 AM
Ariela
Ariela - avatar