Passing pointer to a function in C

By: Emiley J  

This sample program in C demonstrates the concept of passing a pointer as a parameter to a function. In this program, the function "prompt" accepts two pointers. The second parameter (num) is a pointer to the variable i. Since it is a pointer, the function does not return the value. The value is stored in i itself.


void prompt(char *msg, int *num);

int main(void)
  int i;
  prompt("Enter a num: ", &i);
  printf("Your number is: %d", i);

  return 0;

void prompt(char *msg, int *num)
  scanf("%d", num);

Archived Comments

1. i nice programs tks
View Tutorial          By: jai at 2011-05-09 14:09:38

Most Viewed Articles (in C )

Latest Articles (in C)

Comment on this tutorial