Exercises : Answer the following Question

Submitted by Anonymous (not verified) on Sun, 03/10/2013 - 01:12

To help solidify your understanding of this lesson, you are encouraged to answer the quiz questions and finish the exercises provided in the Workshop before you move to the next lesson. The answers and hints to the questions and exercises are given in Appendix E, "Answers to Quiz Questions and Exercises."
Quiz

    Given the following code portion, which variables are global variables, and which ones are local variables with block scope?

    int x = 0;
    float y = 0.0;
    int myFunction()
    {
       int i, j;
       float y;
       . . .
       {
          int x, y;
          . . .
       }
       . . .
    }

    When two variables with the same name are defined, how does the compiler know which one to use?
    Identify the storage class of each declaration in the following code portion:

    int i = 0;
    static int x;
    extern float y;
    int myFunction()
    {
       int i, j;
       extern float z;
       register long s;
       static int index;
       const char str[] = "Warning message.";
       . . .
    }

    Given the following declaration:

    const char ch_str[] = "The const specifier";

    is the ch_str[9] = `-'; statement legal?

Exercises

    Given the following,
        An int variable with block scope and temporary storage
        A constant character variable with block scope
        A float local variable with permanent storage
        A register int variable
        A char pointer initialized with a null character

    write declarations for all of them.
    Rewrite the program in Listing 14.2. This time, pass the int variable x and the float variable y as arguments to the function_1() function. What do you get on your screen after running the program?
    Compile and run the following program. What do you get on the screen, and why?

    #include <stdio.h>
    int main()
    {
       int i;

       for (i=0; i<5; i++){
          int x = 0;
          static int y = 0;
          printf("x=%d, y=%d\n", x++, y++);
       }
       return 0;
    }

   

Related Items

Question and Answer

Question and Answer

    Q Which bit can be used as the sign bit in an integer?

Exercises : Answer the following Question

To help solidify your understanding of this hour's lesson, you are encouraged to answer the quiz questions and finish the exercises provided in the Workshop before you move to the next lesson.

Measuring Data Sizes

Measuring Data Sizes

What Does x?y:z Mean?

What Does x?y:z Mean?

In C, ?: is called the conditional operator, which is the only operator that takes three operands. The general form of the conditional operator is

Using Shift Operators

Using Shift Operators

There are two shift operators in C. The >> operator shifts the bits of an operand to the right; the << operator shifts the bits to the left.

The general forms of the two shift operators are

x >> y