Skip to content

Instantly share code, notes, and snippets.

@Ayrx
Created August 28, 2013 05:49
Show Gist options
  • Save Ayrx/6362515 to your computer and use it in GitHub Desktop.
Save Ayrx/6362515 to your computer and use it in GitHub Desktop.
A simple piece of C code to print out the memory address of a specific environmental variable.
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
char *addr;
if (argc < 2) {
printf("Usage:\n%s <environment variable name>\n", argv[0]);
exit(0);
}
addr = getenv(argv[1]);
if (addr == NULL)
printf("The environment variable %s doesn't exist.\n", argv[1]);
else
printf("%s is located at %p\n", argv[1], addr);
return(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment