c++ main function, argc value is weird if command-line arguments contain * -


a simple piece of c++ code this:

int main(int argc, char **argv){     std::cout << "argc: " << argc << std::endl; } 

compiled g++ -o hello hello.cpp

  • when run ./hello u, output argc: 2;
  • when run ./hello u +, output argc: 3;
  • when run ./hello u *, output argc: 26, why 26?

shell expansion. * expanded shell files in current directory, of there appear 24, , passes them individual arguments program.

since looks call unix shell, use

./hello u \* 

or

./hello u '*' 

Comments

Popular posts from this blog

c# - SharpSsh Command Execution -

python - Specify path of savefig with pylab or matplotlib -

How to run C# code using mono without Xamarin in Android? -