Skip to content

Instantly share code, notes, and snippets.

@mahmoudhossam
Created September 1, 2012 15:21
Show Gist options
  • Save mahmoudhossam/3576996 to your computer and use it in GitHub Desktop.
Save mahmoudhossam/3576996 to your computer and use it in GitHub Desktop.
Trying to calculate a person's age using pointers
#include <stdio.h>
int age(int* year);
int main()
{
printf("Enter your birth year: ");
char buf[50];
char* input = gets(buf);
int year = atoi(input);
int* year_ptr = &year;
int output = age(year_ptr);
printf("You're %d years old.\n", output);
return 0;
}
int age(int* year)
{
return 2012 - *year;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment