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

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -