Exercises : Answer the following Question

Submitted by Anonymous (not verified) on Tue, 02/26/2013 - 00:00

Workshop

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. The answers and hints to the questions and exercises are given in Appendix E, "Answers to Quiz Questions and Exercises."

Quiz

    What is the difference between the = operator and the == operator?
    In the x + - y - - z expression, which operator is the subtraction operator, and which one is the unary minus operator?
    Given x = 15 and y = 4, what do the x / y and (float)x / y expressions return, respectively?
    Is the y *= x + 5 expression equivalent to the y = y * x + 5 expression?

Exercises

   1. Given x = 1 and y = 3, write a program to print out the results of these expressions: x += y, x += -y, x -= y, x -= -y, x *= y, and x *= -y.
    Given x = 3 and y = 6, what is the value of z after the expression  z = x * y == 18 is executed?

   2. Write a program that initializes the integer variable x with 1 and outputs results with the following two statements:

    printf("x++ produces:   %d\n", x++);
    printf("Now x contains: %d\n", x);

    Rewrite the program you wrote in exercise

 

3. This time, include the following two statements:

    printf("x = x++ produces: %d\n", x = x++);
    printf("Now x contains:   %d\n", x);

    What do you get after running the executable of the program? Can you explain why you get such a result?
    The following program is supposed to compare the two variables, x and y, for equality. What's wrong with the program? (Hint: Run the program to see what it prints out.)

    #include <stdio.h>

    main()
    {
       int x, y;

       x = y = 0;
       printf("The comparison result is: %d\n",  x = y);
       return 0;
    }

 

Related Items

The #define and #undef Directives

The #define and #undef Directives

The #define directive is the most common preprocessor directive, which tells the preprocessor to replace every occurrence of a particular character string (that is, a macro name) with a specified value (that is, a macro body).

The C Preprocessor Versus the Compiler

The C Preprocessor Versus the Compiler

One important thing you need to remember is that the C preprocessor is not part of the C compiler.

What Is the C Preprocessor?

If there is a constant appearing in several places in your program, it's a good idea to associate a symbolic name to the constant, and then use the symbolic name to replace the constant throughout the program. There are two advantages to doing so. First, your program will be more readable.

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.

Question and Answer

    Q Why is random access to a disk file necessary?