Skip to content

Instantly share code, notes, and snippets.

@rorhug
Created December 8, 2015 14:43
Show Gist options
  • Save rorhug/b8ed509c3e0a9c17b937 to your computer and use it in GitHub Desktop.
Save rorhug/b8ed509c3e0a9c17b937 to your computer and use it in GitHub Desktop.
for the user to input a number(Z), to place that number in a pointer and to print out the pointer outside the function
#include <stdio.h>
// This shouldn't return anything as it's writing the value to the pointer instead
void scan_int_into_pointer(int * z) // it receives a pointer to an int as an argument
{
printf("enter value=");
scanf("%d", z); // Note: no & because z is already a pointer
// Note: No return value...
}
int main(void)
{
int q; // create an int
// Run the function. I'm passing the address to q (a pointer) not the value of q itself
// Use the & operator to get the address
scan_int_into_pointer(&q);
printf("value=%d\n", q);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment