main函数的参数的用法
说明:
main函数的参数的用法
源代码:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[], char *env[])
{
int i = 0;
printf("Address of Arguements is [%p].\n", (void*)argv[0]);
printf("Argument(s) number is [%d]. List:\n", argc);
for(i=0; i<argc; i++)
printf("\targv[%d]\t[%s]\n", i, argv[i]);
printf("\nAddress of Environments is [%p].\n", (void*)env[0]);
printf("Environment list on this system is:\n");
for(i=0; env[i]!=NULL; i++)
printf("\tenv[%d]\t[%s]\n", i, env[i]);
return 0;
}
程序处理结果(其中环境变量是部分显示):
Address of Arguements is [00821790].
Argument(s) number is [1]. List:
argv[0] [D:\projects\eclipse\cpptest\Debug\cpptest.exe]
Address of Environments is [00822188].
Environment list on this system is:
env[0] [ACE_ROOT=D:\ACE-6.1.0\ACE_wrappers]
env[1] [ACPath=C:\Program Files\Lenovo\Access Connections\]
env[2] [ALCKPath=C:\Program Files\Lenovo\AutoLock]
env[3] [ALLUSERSPROFILE=C:\ProgramData]
env[4] [AMDAPPSDKROOT=C:\Program Files\AMD APP\]
env[5] [APPDATA=C:\Users\Baby\AppData\Roaming]
env[6] [asl.log=Destination=file]
说明
略。