Aim :

Write a C/C++ program thgat output the contents of its Environment list.

Theory :

Environment variables are a set of dynamic named values that can affect the way running processes will behave on a computer.

They are part of the operating environment in which a process runs. For example, a running process can query the value of the TEMP environment variable to discover a suitable location to store temporary files, or the HOME or USERPROFILE variable to find the directory structure owned by the user running the process.

Code :


 #include<stdio.h>
 #include<unistd.h>
 int main(int argc,char *argv[])
 {
  char **ptr;
  extern char **environ;
  for(ptr=environ; *ptr; ptr++)
   printf("%s\n",*ptr);
  return 0;
 }

Output:

  • Open a terminal.
  • Change directory to the file location in both the terminals.
  • Open a file using command followed by program_name
    vi 5a_environlist.c 
    and then enter the source code and save it.
  • Then compile the program using
    gcc 5a_environlist.c
  • If there are no errors after compilation execute the program using
    ./a.out 

Screenshot :

Not Available Not Available