Exercises : Answer the following Question

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

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

    Given the following function declarations, which ones are functions with a fixed number of arguments, which ones are functions with no arguments, and which ones are functions with a variable number of arguments?
        int function_1(int x, float y);
        void function_2(char *str);
        char *asctime(const struct tm *timeptr);
        int function_3(void);
        char function_4(char c, …);
        void function_5(void);
    Which one of the following two expressions is a function definition?

    int function_1(int x, int y);
    int function_2(int x, int y){return x+y;}

    What is the data type returned by a function when a type specifier is omitted?

    Of the following function declarations, which ones are illegal?
        double function_1(int x, ...);
        void function_2(int x, int y, ...);
        char function_3(...);
        int function_4(int, int, int, int);

Exercises

    Rewrite the program in Listing 15.2. This time use the format specifier %c, instead of %s, to print out the character string of the local time on your computer.
    Declare and define a function, called MultiTwo(), that can perform multiplication on two integer variables. Call the MultiTwo() function from the main() function and pass two integers to MultiTwo(). Then print out the result returned by the MultiTwo() function on the screen.
    Rewrite the program in Listing 15.3. This time, make a function that takes a variable number of int arguments and performs the operation of multiplication on these arguments.
    Rewrite the program in Listing 15.3 again. This time, print out all arguments passed to the AddDouble() function. Does va_arg() fetch each argument in the same order (that is, from left to right) of the argument list passed to AddDouble()?

Related Items

Manipulating Bits

Manipulating Bits

In previous hours, you learned that computer data and files are made of bits (or bytes). There is even an operator in C_the sizeof operator_that can be used to measure the number of bytes for data types.

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 */
}