0
How can you print a variable before you add a value to it?
This is the code that works #include <iostream> using namespace std; void printSomething(int x) { cout << x; } int main() { printSomething(42); } But shouldn't the code be #include <iostream> using namespace std; void printSomething(int x) { } int main() { printSomething(42); cout << x; }
2 Answers
0
in the second code printSomthing(int x){ } does litterally nothing .. it has no implementation so it does nothing ..
you may try this code
#include <iostream>
using namespace std;
void PrintSomething(int newvalue, int &x)
{
x = newvalue;
}
void main()
{
int x;
PrintSomething(42,x);
cout << x;
}
0
in this case I recommend the function call should be ChangeValue instead of PrintSomething .. unless you stick with your first code such that PrintSomething actually does cout something. I hope that helped.