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

The while Loop

The while Loop

The while statement is also used for looping. Unlike the situation with the for statement, there is only one expression field in the while statement.

The general form of the while statement is

while (expression) {

Question and Answer

Question and Answer

    Q How does a for loop work?

Exercises : Answer the following Question

To help you solidify your understanding of this hour's lesson, you are encouraged to try to answer the quiz questions and finish the exercises provided in the Workshop before you move to the next lesson.

 

Working with the Cast Operator

Playing with the Cast Operator

In C, you can convert one data type to a different one by prefixing the cast operator to the operand.

The general form of the cast operator is

(data-type)x

Question and Answer

Question and Answer

    Q What is the difference between the pre-increment operator and the post-increment operator?