+ 1

C++ argc argv

how can use these arguments(argc,argv) in any function ? (no main function) somthing like this: int hello(int argc,char **argv){ return argc; } hello ("hi","hello",hey"); //output 3 hello ("hi"); //output 1

3rd Apr 2021, 12:16 PM
ali
ali - avatar
6 ответов
+ 2
https://code.sololearn.com/cgZMln6swhg2/?ref=app quick example..try search on google for detail
3rd Apr 2021, 1:21 PM
durian
durian - avatar
+ 1
do you mean u want to pass any amount of arguments?
3rd Apr 2021, 1:10 PM
durian
durian - avatar
+ 1
try to consider function overloading first cause its the easiest other way is to use variadic function/template..it is a little bit complex but worth learning
3rd Apr 2021, 1:14 PM
durian
durian - avatar
+ 1
Can you give me example?
3rd Apr 2021, 1:15 PM
ali
ali - avatar
+ 1
argc argv are just parameters you can have them in any function but its not going to get called automatically. You should call the thing and pass values yourself
5th Apr 2021, 4:33 AM
Nader Jafari
Nader Jafari - avatar
0
Yes like *args python
3rd Apr 2021, 1:10 PM
ali
ali - avatar