what is the different between local variable and parameter variable and golbal variable in c language
thanks
thanks
#include <stdio.h>
void PassByValue(int);
void PassByReference(int*);
//this is a global variable
int global1 = 1;
void main()
{
printf("global1 is: %i\r\n",global1);
//this variable has local scope to main()
//it will cease to exist after main() has ended
int x = 2;
printf("x is: %i\r\n",x);
PassByValue(x);
printf("x is: %i\r\n",x);
PassByReference(&x);
printf("x is: %i\r\n",x);
}
void PassByValue(int value)
{
//this will modify the value of the
//variable passed in
//value will only contain the value
//until the function returns
value = value * 2;
}
void PassByReference(int* reference)
{
//this will modify the contents of the
//location pointed to by reference
//reference will contain the value
//until the variable it points to
//no longer exists
*reference = (*reference) * 2;
}