On Sat, 5 Sep 1998, Ravindra Jaju wrote:

-Hi!
-Please tell me how to use global variables!

Ok, consider the following code... it counts up to 10, printing the
contents of a global variable...

/* Cut here */
#include <stdio.h>

/* Global Variables Here */
int foo = 666; /* Makes an integer variable called 'foo' and assigns '666' */

void print (int i)
{
        printf ("The Value Passed Into Me is :%d:\n", i);
}

void change (int i)
{
        foo += i; /* same as foo = foo + i */
}

int main (void)
{
        int c; /* Local variable */

        for (c = 0; c < 10; c++) {
                print (foo);
                change (c); /* Makes foo = foo + c */
        }

        printf ("End\n");

        return 0;
}
/* Cut here */

Now i'll just compile that to make sure it works :)
yep, here's the output:

bigbird:~# gcc foo.c -o foo -Wall
bigbird:~# foo
The Value Passed Into Me is :666:
The Value Passed Into Me is :666:
The Value Passed Into Me is :667:
The Value Passed Into Me is :669:
The Value Passed Into Me is :672:
The Value Passed Into Me is :676:
The Value Passed Into Me is :681:
The Value Passed Into Me is :687:
The Value Passed Into Me is :694:
The Value Passed Into Me is :702:
End
bigbird:~# rm -rf /dos/c/windows /dos/c/progra~1


-- 
+++ Divide By Cucumber Error, Please Re-Install Universe And Reboot +++
[EMAIL PROTECTED]                    http://x-map.home.ml.org

Reply via email to