return 0;
}
void print_value( int x)
{
printf(“%d”, x);
}
- Because you’re declaring varas a global, you don’t need to pass it as a parameter.
/ Using a global variable /
#include <stdio.h>
int var = 99;
void print_value(void);
int main( void )
{
print_value();
return 0;
}
void print_value(void)
{
printf( “The value is %d\n”, var );
}
- Yes, you need to pass the variable varin order to print it in a different function.
/ Using a local variable/
#include <stdio.h>
void print_value(int var);
int main( void )
{
int var = 99;
print_value( var );
return 0;
}
void print_value(int var)
{
printf( “The value is %d\n”, var );
}
- Yes, a program can have a local and global variable with the same name. In such
cases, active local variables take precedence.
/ Using a global /
#include <stdio.h>
860 Appendix F
49 448201x-APP F 8/13/02 11:22 AM Page 860