Home > Articles > Programming > C/C++

  • Print
  • + Share This
This chapter is from the book

Workshop

The Workshop provides quiz questions to help you solidify your understanding of the material covered and exercises to provide you with experience in using what you’ve learned.

Quiz

  1. What is the term for a group of one or more C statements enclosed in braces?
  2. What is the one component that must be present in every C program?
  3. How do you add program comments, and why are they used?
  4. What is a function?
  5. C offers two types of functions. What are they, and how are they different?
  6. What is the #include directive used for?
  7. Can comments be nested?
  8. Can comments be longer than one line?
  9. What is another name for an include file?
  10. What is an include file?

Exercises

  1. Write the smallest program possible.
  2. Consider the following program:
    1:  /* ex02-02.c */
    2:  #include <stdio.h>
    3:
    4:  void display_line(void);
    5:
    6:  int main(void)
    7:  {
    8:      display_line();
    9:      printf("\n Teach Yourself C In One Hour a Day!\n");
    10:     display_line();
    11:
    12:      return 0;
    13: }
    14:
    15: /* print asterisk line */
    16: void display_line(void)
    17: {
    18:     int counter;
    19:
    20:     for( counter = 0; counter < 30; counter++ )
    21:         printf("*" );
    22: }
    23: /* end of program */
    1. What line(s) contain statements?
    2. What line(s) contain variable definitions?
    3. What line(s) contain function prototypes?
    4. What line(s) contain function definitions?
    5. What line(s) contain comments?
  3. Write an example of a comment.
  4. What does the following program do? (Enter, compile, and run it.)

    1:  /* ex02-04.c */
    2:  #include <stdio.h>
    3:
    4:  int main(void)
    5:  {
    6:     int ctr;
    7:
    8:     for( ctr = 65; ctr < 91; ctr++ )
    9:         printf("%c", ctr );
    10:
    11:    printf("\n");
    11:    return 0;
    12: }
    13: /* end of program */
  5. What does the following program do? (Enter, compile, and run it.)

    1:  /* ex02-05.c */
    2:  #include <stdio.h>
    3:  #include <string.h>
    4:  int main(void)
    5:  {
    6:      char buffer[256];
    7:
    8:      printf( "Enter your name and press <Enter>:\n");
    9:      fgets( buffer );
    10:
    11:      printf( "\nYour name has %d characters and spaces!",
    12                        strlen( buffer ));
    13:
    14:     return 0;
    15: }
  • + Share This
  • 🔖 Save To Your Account