Exercises : Answer the following Question

Submitted by tushar pramanick on Mon, 03/11/2013 - 00:14

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's wrong with the following macro definition?

    #define  ONE   1;

    What is the final value assigned to result after the assignment statement is executed?

    #define ONE       1
    #define NINE      9
    #define EXPRESS   ONE + NINE
    result = EXPRESS * NINE;

    What message will be printed out from the following code segment?

    #define MACRO_NAME  0
    #if MACRO_NAME
       printf("Under #if.\n");
    #else
       printf("Under #else.\n");
    #endif

    What message will be printed out from the following code segment?

    #define MACRO_NAME  0
    #ifdef MACRO_NAME
       printf("Under #ifdef.\n");
    #endif
    #ifndef MACRO_NAME
       printf("Under #ifndef.\n");
    #endif

Exercises

    In Hour 18, "More Data Types and Functions," you learned how to define enum data. Rewrite the program in Listing 18.1 with the #define directive.
    Define a macro name that can multiply two arguments. Write a program to calculate the multiplication of 2 and 3 with the help of the macro. Print out the result of the program.
    Rewrite the program in Listing 23.2 with the #if, #elif, and #else directives.
    Rewrite the program in Listing 23.3 with nested #if directives.

 

***

Related Items

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

The Basics of Disk File I/O

The Basics of Disk File I/O

Now let's focus on how to open and close a disk data file and how to interpret error messages returned by I/O functions.