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

Everything Is Logical

Everything Is Logical

Now, it's time for you to learn about a new set of operators: logical operators.

There are three logical operators in the C language:
&&     The logical AND operator
||     The logical OR operator

Question and Answer

    Q Why do we need the sizeof operator?

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.

Playing with an Infinite Loop

Playing with an Infinite Loop

If you have a for statement like this,

for ( ; ; ){
  /* statement block */
}

Adding More Expressions into for

Adding More Expressions into for

The C language allows you to put more expressions into the three expression fields in the for statement. Expressions in a single expression field are separated by commas.