title: Why I can't print out environment variables in gdb?
body: <pre><code>#include &lt;unistd.h&gt;
  #include &lt;stdio.h&gt;
  
  extern char **environ;
  int main(int argc, char *argv[]) { 
    int i = 0;
    while(environ[i]) {
      printf("%s\n", environ[i++]);
    }
    return 0;
  }
  </code></pre>
  
  <p>Here's my ops:</p>
  
  <pre><code>(gdb) n
  8       printf("%s\n", environ[i++]);
  (gdb) p environ[i]
  Cannot access memory at address 0x0
  (gdb) n
  LOGNAME=root
  7     while(environ[i]) {
  </code></pre>
  
  <p>As you can see,<code>printf</code> can print out <code>environ[i]</code>,but <code>p environ[i]</code> gives me <code>Cannot access memory at address 0x0</code>,why?</p>