fork download
  1. //http://e...content-available-to-author-only...u.tw/~klim/unix-p/usp-1092.html
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. int main(int argc, char *argv[], char *env[]) {
  6. int i, j;
  7. printf("argc is %d\n", argc);
  8. for (i = 0; i < argc; i++)
  9. printf("argv[%d]: %s\n", i, argv[i]);
  10. for (i = 0; env[i] != NULL; i++)
  11. printf("environ[%d]: %s\n", i, env[i]);
  12. printf("\n");
  13. printf("argc is resided at %p\n", &argc);
  14. printf("argv is resided at %p\n", &argv);
  15. printf("environ is resided at %p\n", &env);
  16. printf("argv[] is resided at %p\n", &*argv);
  17. printf("environ[] is resided at %p\n", &*env);
  18. for (j = 0; j <= argc; j++)
  19. printf("value of argv[%2d] is %p\n", j, argv[j]);
  20. int env_count = i;
  21. for (i = 0; env[i] != NULL; i++)
  22. printf("value of env [%2d] is %p\n", i, env[i]);
  23. }
  24.  
Success #stdin #stdout 0s 4900KB
stdin
Standard input is empty
stdout
argc is 1
argv[0]: ./prog
environ[0]: PWD=/home/FTD2c2
environ[1]: TMPDIR_GLOBAL=/tmp/6005faab-81d6-4c57-b7e5-c2ae49b2e58a
environ[2]: HOME=/home/FTD2c2
environ[3]: LANG=en_US.UTF-8
environ[4]: TMPDIR=/tmp/kPM4yE
environ[5]: WORKSPACE=/tmp/6005faab-81d6-4c57-b7e5-c2ae49b2e58a
environ[6]: SHLVL=0
environ[7]: PATH=/usr/local/bin:/usr/bin:/bin

argc      is resided at 0x7fff34d5c07c
argv      is resided at 0x7fff34d5c070
environ   is resided at 0x7fff34d5c068
argv[]    is resided at 0x7fff34d5c178
environ[] is resided at 0x7fff34d5c188
value of argv[ 0] is 0x7fff34d5df02
value of argv[ 1] is (nil)
value of env [ 0] is 0x7fff34d5df09
value of env [ 1] is 0x7fff34d5df1a
value of env [ 2] is 0x7fff34d5df52
value of env [ 3] is 0x7fff34d5df64
value of env [ 4] is 0x7fff34d5df75
value of env [ 5] is 0x7fff34d5df88
value of env [ 6] is 0x7fff34d5dfbc
value of env [ 7] is 0x7fff34d5dfc4