当实参传给main函数之后,argv的第一个元素指向程序的名字或者一个空字符串
前半句话我知道,主要是后半句话,argv[0]='\0',这算啥?
ringa_lee2017-04-17 12:08:53
argv[0] is the pointer to the initial character of a null-terminated multibyte strings that represents the name used to invoke the program itself (or, if this is not supported by the execution environment, argv[0][0] is guaranteed to be zero).
http://en.cppreference.com/w/c/language/main_function
argv[0] is the pointer to the initial character of a null-terminated multibyte strings that represents the name used to invoke the program itself (or an empty string "" if this is not supported by the execution environment).
http://en.cppreference.com/w/cpp/language/main_function
黄舟2017-04-17 12:08:53
First you have to know how to create a process.
Taking the Windows platform as an example, the standard is to create it through CreateProcess
CreateProcess MSDN: https://msdn.microsoft.com/zh-cn/library/ms682425(v=vs.85).aspx
BOOL WINAPI CreateProcess(
_In_opt_ LPCTSTR lpApplicationName,
_Inout_opt_ LPTSTR lpCommandLine,
_In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,
_In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
_In_ BOOL bInheritHandles,
_In_ DWORD dwCreationFlags,
_In_opt_ LPVOID lpEnvironment,
_In_opt_ LPCTSTR lpCurrentDirectory,
_In_ LPSTARTUPINFO lpStartupInfo,
_Out_ LPPROCESS_INFORMATION lpProcessInformation
);
The first parameter is the absolute path of the program, and the second is the command line parameter. If the first parameter exists and the second is empty, then argv will be empty.
Under Linux, the internal implementation is mainly
int execle(const char *path, const char *arg , ..., char * const envp[]);
That is, arg is empty.
In Windows, open the Task Manager and select Show command line parameters. There are many system processes that do not have command line parameters.
In most cases, at least one command line argument is itself.