Submitted by tushar pramanick on Fri, 03/08/2013 - 00:25

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 x = 0, will the arithmetic operations inside the following if statement be performed?

    if (x != 0)
       y = 123 / x + 456;


    Given x = 4, y = 2, and operator = `-', what is the final value of x after the following switch statement is executed?

    switch (operator){
       case `+':  x += y;
       case `-':  x -= y;
       case `*':  x *= y;
       case `/':  x /= y;
       default:   break;
    }


    Similarly to in question 2, using x = 4, y = 2, and operator = `-', what is the final value of x after the following switch statement is executed?

    switch (operator){
       case `+':  x += y; break;
       case `-':  x -= y; break;
       case `*':  x *= y; break;
       case `/':  x /= y; break;
       default:   break;
    }


    What is the value of the integer variable x after the following code is executed?

    x = 1;
    for (i=2; i<10; i++){
       if (i%3 == 0)
          continue;
       x += i;
    }


Exercises

    Rewrite the program in Listing 10.1. This time, use the logical expression i%6 == 0 in the if statement.
    Rewrite the program in Listing 10.1 by using nested if statements.
    Write a program to read characters from the standard I/O. If the characters are A, B, and C, display their numeric values on the screen. (The switch statement is required.)
    Write a program that keeps reading characters from the standard input until the character q is entered.
    Rewrite the program in Listing 10.7. This time, instead of skipping 3 and 5, skip the integer that can be divided evenly by both 2 and 3.

Related Items

মডুলার C প্রোগ্রামিং (Modular C Programming)

কেবল মাত্র একটি ফাংশন দিয়ে কোনো বড়ো জটিল সমস্যা সমাধানের চেষ্টা করা ভাল প্রোগ্রামিংয়ের পদ্ধতি নয়। সঠিক পদ্ধতি হ'ল সমস্যাটিকে কয়েকটি ছোট ছোট এবং সরল টুকরো করে ফেলা যাতে তা আরও বিশদে বোঝা যায় । তারপরে এই ছোট এবং সরল সমস্যাগুলি সমাধান করার জন্য ছোট ছোট ফাংশন ব্লক তৈরি করা এবং পরে সেগুলি নিয়মানুযায়ী সংযোজিত করা ।

Programming Style

Programming Style

In this section, I'd like to briefly highlight some points that will help you write clean programs that can easily be read, understood, and maintained.

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.

Question and Answer

    Q Is the C preprocessor part of the C compiler?

    A No. The C preprocessor is not part of the C compiler. With its own line-oriented grammar and syntax, the C preprocessor runs before the compiler in order to handle named constants, macros, and inclusion of files.

Compiling Your Code Under Conditions

Compiling Your Code Under Conditions

You can select portions of your C program that you want to compile by using a set of preprocessor directives. This is useful, especially when you're testing a piece of new code or debugging a portion of code.