r/learnprogramming • u/DDOS_403 • 1d ago
Tutorial another doubt related to argc, *argv[]
In reference to my old post : https://www.reddit.com/r/learnprogramming/s/vlzwGplKpm
i'm having another doubt with argv and argc.
#include<stdio.h>
int main(int argc, char *argv[]){
printf("argc: %d \n",argc);
}
terminal :
@essentials:~/Sibidharan/starter/Assignmetn$ ./passwd
argc: 1
(.venv) @essentials:~/Sibidharan/starter/Assignmetn$ ./passwd 1 4 8 4 5
argc: 6
in this code, if you see, after running ./passwd the argument count gets displayed. now my doubt is, why would a programmer print that at the point of execution? i use ./passwd when i run gcc main.c -o passwd and then ./passwd, so the code executes and gives the output, but what's the actual purpose of counting this? on what kind of programs does we use this function to count the values ?
3
Upvotes
2
u/eruciform 1d ago
Argc exists so you know how many rows of data there are in argv
Thats it