I am running this program with the values 10,20,30 specified on the command line.
int main(int argc , char **argv) { printf("\n Printing the arguments of a program \n"); printf("\n The total number of arguments in the program is %d",argc); while(argc>=0) { printf("%s ",argv[argc]); argc--; } return 0; }
Outputs The total number of arguments in the program is 4 (null) 30 20 10./a.out
Where did this (zero) come from?
argv[0](as far as possible) should be something that identifies the program being executed. argv[1]through argv[argc-1]are the arguments that were actually entered on the command line. argv[argc]it is required to be a null pointer (§5.1.2.2.1 / 2).
argv[0]
argv[1]
argv[argc-1]
argv[argc]
argc- total number of elements in the array argv; they are numbered from 0to argc - 1. You print five values, and only the last four are valid.
argc
argv
0
argc - 1
, , C. C 0, 1, 2,...
argv [4], argv [3], argv [2], argv [1], argv [0], argv [3], argv [2], argv [1], argv [0].
, .
argc , argv[0] to argv[argc-1]. argv [argc-1].
argv[0] to argv[argc-1]
, , , , . , .
0 . , , , . https://stackoverflow.com/questions/393462?tab=votes&page=1#tab-top
, , while(argc >= 0) , , . , argc argc-1.
while(argc >= 0)
, -, , argv [0] - , argc , , argc = 4, , ...
, , C , argv [argc] NULL, , , 1 - argc-1 ... ( )
(null) 30 20 10, argv [argc], 10,20,30, 4 ( ), argv [argc] argv [4], .. ( [0], argv [0] ... argv 1 .... ..... argv [4] , ), , (null) 30 20 10.
printf("%s ",argv[argc-1]);
C -
Source: https://habr.com/ru/post/1757346/More articles:How to disable GestureListener in android? - androidWhy use "// ->" in javascript - javascriptКонкатенация строк в Python - pythonUsing Bind in a TextBox displays related data outside the TextBox control - c #Any advantage of using "static" for private consts? - actionscriptEnable J2EE Web Application Resource Cache - jsf-2Is there any way to check if updating SVN will lead to a conflict? - svnСлайд в анимации при обновлении экрана на Android - androidFileStream: T-SQL vs Win32 - sql-serverInsert / Insert a File into a DOCX File - File Type Definition - .netAll Articles