Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pointer to console arguments

Tags:

c

As a C newbie, I have trouble to understand the following:

 int main(int argc, char *argv[]) {
     char **inputs = argv + 1;

char **inputs is a pointer to char *argv[] which is also a pointer, right? But why I have to add the "+1" at the end? Will this be an extra space for the '\0' character?

like image 489
Markus Avatar asked Jan 10 '23 03:01

Markus


2 Answers

argv[0], or the first argument, is the string holding the name of your program.

like image 80
Ashalynd Avatar answered Jan 14 '23 00:01

Ashalynd


argv[0] is the program you're currently running
argv[1+] are the arguments passed to the program
Perhaps not the best reference: https://www.gnu.org/software/gawk/manual/html_node/ARGC-and-ARGV.html

like image 28
guest Avatar answered Jan 13 '23 22:01

guest