getenv() - Utility Function

How is Utility function "getenv()" used in C++?
How to Get the Environment String using C++?


getenv() is a Utility Function that returns a pointer to the environmental variable which is given as an argument.This function returns a null terminated string or a NULL, if the variable does'nt exist.

Syntax to get the Environment String:

char *getnev(const char *name);

Example :

#include <stdlib.h>
#include <stdio.h>
int main ()
printf ("The current path is: %s",getenv("LIB"));
return 0;

Result :

The current path is: (null)

In the above example getenv() function returns a "NULL" value since the environmental variable for "LIB" is not available.

C++ Tutorial

Ask Questions

Ask Question