So I'm beginning to learn C++ and came upon this example--
#include <iostream>
void doIt(int x)
{
x = 3;
int y = 4;
std::cout << "doIt: x = " << x << " y = " << y << std::endl;
}
int main()
{
int x = 1;
int y = 2;
std::cout << "main: x = " << x << " y = " << y << std::endl;
doIt(x);
std::cout << "main: x = " << x << " y = " << y << std::endl;
return 0;
}
--and for the sequence where doIt() is called, doit: x = 3 y = 4 is printed. Maybe there is some unknown thing I could search to better understand what happened, but essentially what I'm wondering is whether x was passed to the function as a variable or as its value (1). If it were passed as 1, wouldn't there be an error? Does this mean that the function would require an integer variable rather than a standalone integer? This program was intended to show how these variables are local, but I'm not sure how it all fits together.