[Skip Navigation] [CSUSB] / [CNS] / [Comp Sci & Eng Dept] / [R J Botting] /[CS320 Course Materials] [Text Version] lab/07.html Thu Apr 23 13:34:16 PDT 2009
Labs: [01] [02] [03] [04] [05] [06] [07] [08] [09] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20]

Contents


    CSci320 Programming Languages Lab 07

    Here is a C++ program [ sizes.cpp ] for you to download and work with. It has one line that needs removing.

    The sizeof operator calculates the number of bytes of storage the compiler allocates to the operand.

    Fix any compilation errors and make it run.

    Questions

    1. Do all pointer types (T*) need the same storage?
    2. Does the size of a pointer (T*) reflect the size of thing pointed at(T)?
    3. Does the size of an array vary with the number of elements?
    4. Does the size of a vector vary with the number of elements? (and where does the rest of the vector get hidden?)


      Is the sizeof operator static or dynamic?


    To answer the questions you might want to make some more changes.

    Deliverable: you should prepare a new page for your growing WWW site that has two or three paragraphs explaining what you have learned about C++ data types. Answer each question in a paragraph that includes an explanation! The page should include a link to the source code for the final version of the program that you use. Graphics are not needed. The whole page should be linked to the growing list of laboratory pages on your index/home page.

    Deadline: I will be assigning grades at the end of the lab depending on how much of the deliverables are complete and correct. I will checking that your paragraphs have no gross spelling mistakes and that they say something true and interesting about C++.

    If you have time -- Pointers

    You can compile it and run it, but can you explain why it does what it does? [ horror.c ]

    Why Learn about Pointers?

     Hello Dr. Concepcion,
     I just had an personal interview with XXXX. Everything went well. Yyyy
     was much easier to talk to in person. I did the test well (one of the
     interviewer said)
     The test was mainly pointers. Thanks to Dr Botting, he trained me good
     with pointer in csci320.
     There was one 6-part question that I scored 5 out of 6. They said no one
     ever get them all right.
     The test format was extremely unusual. It asked "what would happen if
     .." and doesn't give you a clue what
     they expect the format of the answers would be.

    Check the next class

    [ ../08.html ]

End