Review Questions

I l @ ve RuBoard

Review Questions

  1. What's wrong with this template?

     structure {        char itable;        int  num[20];        char * togs } 
  2. Here is a portion of a program. What will it print?

     #include <stdio.h> struct house {     float sqft;     int rooms;     int stories;     char address[40]; }; int main(void) {   struct house fruzt = {1560.0, 6, 1, "22 Spiffo Road"};   struct house *sign;   sign = &fruzt;   printf("%d %d\n", fruzt.rooms, sign->stories);   printf("%s \n", fruzt.address);   printf("%c %c\n", sign->address[3], fruzt.address[4]);   return 0; } 
  3. Devise a structure template that will hold the name of a month, a three-letter abbreviation for the month, the number of days in the month, and the month number.

  4. Define an array of 12 structures of the sort in Question 3 and initialize it for a non-leap year.

  5. Write a function that, when given the month number, returns the total days in the year up to and including that month. Assume that the structure template of Question 2 and an appropriate array of such structures are declared externally.

  6. Given the following typedef , declare a ten-element array of the indicated structure. Then, using individual member assignment (or the string equivalent), let the third element describe a Remarkatar lens of focal length 500 mm and aperture f/2.0.

     typedef struct lens {    /* lens descriptor */     float foclen;        /* focal length,mm */     float fstop;         /* aperture        */     char brand[30];      /* brand name      */ } LENS; 
  7. Consider the following programming fragment:

     struct name {         char first[20];         char last[20]; }; struct bem {         int limbs;         struct name title;         char type[30]; }; struct bem * pb; struct bem deb = {         6,         {"Berbnazel", "Gwolkapwolk"},         "Arcturan" }; pb = &deb; 
    1. What would each of the following statements print?

       printf("%d\n", deb.limbs); printf("%s\n", pb->type); printf("%s\n", pb->type + 2); 
    2. How could you represent "Gwolkapwolk" in structure notation (two ways)?

    3. Write a function that takes the address of a bem structure as its argument and prints the contents of that structure in the form shown below. Assume that the structure template is in a file called starfolk.h .

        Berbnazel Gwolkapwolk is a 6-limbed Arcturan.  
  8. Consider the following declarations:

     struct fullname {                 char fname[20];                 char lname[20];                 }; struct bard     {                 struct fullname name;                 int born;                 int died;                 }; struct bard willie; struct bard *pt = &willie; 
    1. Identify the born member of the willie structure using the willie identifier.

    2. Identify the born member of the willie structure using the pt identifier.

    3. Use a scanf() call to read in a value for the born member using the willie identifier.

    4. Use a scanf() call to read in a value for the born member using the pt identifier.

    5. Construct an identifier for the third letter of the first name of someone described by the willie variable.

    6. Construct an expression representing the total number of letters in the first and last names of someone described by the willie variable.

  9. Define a structure template suitable for holding the following items: the name of an automobile, its horsepower, its EPA city-driving mpg rating, its wheelbase, and its year. Use car as the template tag.

  10. Suppose you have this structure:

     struct gas {         float distance;         float gals;         float mpg; }; 

    Devise a function that takes a struct gas argument. Assume that the passed structure contains the distance and gals information. Have the function calculate the correct value for the mpg member and return the now completed structure.

  11. Declare a pointer to a function that returns a pointer to char and that takes a pointer to char and a char as arguments.

  12. Declare four functions and initialize an array of pointers to point to them. Each function should take two double arguments and return a double .

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