Created
September 1, 2012 15:21
-
-
Save mahmoudhossam/3576996 to your computer and use it in GitHub Desktop.
Trying to calculate a person's age using pointers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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