< Back
Page 6 of 6
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
- What is the term for a group of one or more C statements enclosed in braces?
- What is the one component that must be present in every C program?
- How do you add program comments, and why are they used?
- What is a function?
- C offers two types of functions. What are they, and how are they different?
- What is the #include directive used for?
- Can comments be nested?
- Can comments be longer than one line?
- What is another name for an include file?
- What is an include file?
Exercises
- Write the smallest program possible.
- 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 */
- What line(s) contain statements?
- What line(s) contain variable definitions?
- What line(s) contain function prototypes?
- What line(s) contain function definitions?
- What line(s) contain comments?
- Write an example of a comment.
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 */
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: }
< Back
Page 6 of 6