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

More Examples of Disk File I/O

More Examples of Disk File I/O

The following sections show several more examples of disk file I/O, such as reading and writing binary data and redirecting the standard streams. Three more I/O functions, fscanf(), fprintf(), and freopen(), are introduced, too.

Random Access to Disk Files

Random Access to Disk Files

Exercises : Answer the following Question

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.

Question and Answer

    Q What are the differences between a text stream and a binary stream?

Reading and Writing Disk Files

Reading and Writing Disk Files