Skip to main content
Engineering LibreTexts

5.3: Exercises

  • Page ID
    35823
  • Exercise \(\PageIndex{1}\)

    Assume a function declares a variable like so: static int x=0; The function increments the variable and then prints its value. What does the function print out on the tenth call to the function? How would this change if the static keyword was not used?

    Exercise \(\PageIndex{2}\)

    Consider the following snippet of code:

    void doug( void )
    {
        int x=0;
        
        x=x+1;
        printf( “%d\n”, x );
    }
    void dinsdale( void )
    {
        int x=20;
        
        x=x+1;
        printf( “%d\n”, x );
    }
    

    Suppose you call doug() five times in a row and then call dinsdale() five times in a row. What would the resulting output look like?