Review Questions

I l @ ve RuBoard

Review Questions

  1. Run Listing 4.1 again, but this time give your first and last name when it asks you for your first name . What happens? Why?

  2. Assuming that each of the following examples is part of a complete program, what will each one print?

    1.  printf("He sold the painting for $%2.2f.\n", 2.345e2); 
    2.  printf("%c%c%c\n", 'H', 105, ''); 
    3.  #define Q "His Hamlet was funny without being vulgar." printf("%s\nhas %d characters.\n", Q, strlen(Q)); 
    4.  printf("Is %2.2e the same as %2.2f?\n", 1201.0, 1201.0); 
  3. In Question 2.c., what changes could you make so that string Q is printed out enclosed in quotes?

  4. It's find the error time!

     define B booboo define X 10 main(int) {    int age;    char name;    printf("Please enter your first name.");    scanf("%s", name);    printf("All right, %c, what's your age?\n", name);    scanf("%f", age);    xp = age + X;    printf("That's a %s! You must be at least %d.\n", B, xp);    rerun 0; } 
  5. Suppose a program starts like this:

     #define BOOK "War and Peace" int main(void) {    float cost =12.99;    float percent = 80.0; 

    Construct a printf() statement that uses BOOK , cost , and percent to print the following:

     This copy of "War and Peace" sells for .99. That is 80% of list. 
  6. What conversion specification would you use to print each of the following?

    1.  A decimal integer with a field width equal to the number of digits ____________ 
    2.  A hexadecimal integer in the form 8A in a field width of 4 _____ 
    3.  A floating-point number in the form of 232.346 with a field width of 10 ______ 
    4.  A floating-point number in the form 2.33e+002 with a field width of 12 _____ 
    5.  A string left-justified in a field of width 30 _____ 
  7. Which conversion specification would you use to print each of the following?

    1.  An  unsigned long  integer in a field width of 15. 
    2.  A hexadecimal integer in the form 0x8a in a field width of 4. 
    3.  A floating-point number in the form 2.33E+02 that is left-justified in a field width of 12. 
    4.  A floating-point number in the form +232.346 in a field width of 10. 
    5.  The first 8 characters of a string in a field 8 characters wide. 
  8. What conversion specification would you use to print each of the following?

    1.  A decimal integer having a minimum of 4 digits in a field width of 6 _____ 
    2.  An octal integer in a field whose width will be given in the argument list _____ 
    3.  A character in a field width of 2 ____ 
    4.  A floating-point number in the form +3.13 in a field width equal to the number of characters in the number. 
    5.  The first 5 characters in a string left-justified in a field of width 7_____ 
  9. For each of the following input lines, provide a scanf() statement to read it. Also declare any variables or arrays used in the statement.

    1.  101 
    2.  22.32 and 8.34E-09 
    3.  Chelsea 
    4.  catch 22 
    5.  catch 22 (but skip over catch) 
  10. What is whitespace?

  11. Suppose that you would rather use parentheses than braces in your programs. How well would the following work?

     #define ( { #define ) } 
I l @ ve RuBoard


C++ Primer Plus
C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2000
Pages: 314
Authors: Stephen Prata

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net