/* example that demonstrates the use of functions */ #include #include float P,M; /*Global variables declared here */ int world (int z) { int n; /* a local variable only exists within the function */ printf("\nHello World\n"); n = 66; return (n); } void swap (int *x, int *y) { int *temp; temp = *x; *x = *y; *y = temp; } void strfunc(char s[80]) { printf("In strfunc s = %s\n",s); strcpy(s,"Its feet were white and grey\n"); } int main (void) { int z,w; printf("\nCalling function\n"); w = world(z); z = 3; w = 9; swap(&z,&w); printf("Z = %i, W = %i\n",z,w); /*functions in c call by value i.e. z cannot be changed by the function. However, global variables can be changed and a function can also change the values to which pointers point */ printf("\nReturned from functions\n"); char s1[80] = "Mary had a little lamb\n"; strfunc(s1); strfunc(s1); }