A pointer to a string of the format `NAME=VALUE`, where `NAME` is the name of the environment variable and `VALUE` is its value. The string must persist in memory as long as the environment variable is needed.
Read more about parameters of putenv in parameters section
The putenvfunction in C language Changes or adds a value to the environment.
The putenv function adds or changes the value of environment variables. It takes a string of the form name=value and places it in the environment list. If the name already exists in the environment, its value is changed to the new value. If the name does not exist, a new entry is created. The string passed to putenv becomes part of the environment, so altering the string after a call to putenv affects the environment.
The putenvfunction takes 1
parameter:
•
char * `string`: A pointer to a string of the format `NAME=VALUE`, where `NAME` is the name of the environment variable and `VALUE` is its value. The string must persist in memory as long as the environment variable is needed.
Adds or modifies an environment variable specified by the string `NAME=VALUE`. The function directly uses the memory pointed to by `string` without copying it, so the string must not be modified or freed while in use. Returns `0` on success or a nonzero value on failure.
The putenv function return value :
Returns zero on success, or a non-zero value if an error occurs
Output
This example demonstrates how to use putenv to set an environment variable and then retrieve its value using getenv.