Thread: New with C...need help!!

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    6

    New with C...need help!!

    Hi, I'm really new to C programming and I don't know the answers to a few practice exam questions that the teacher provided for us to review with. If anyone could help me out that would wonderful :-) thank you!

    1) Which of the following would be passed by address without the use of the address operator?
    A. An array of structures
    B. A single structure
    C. Any element of a structure.
    D. None of the Above

    I think it is A...not at all sure though

    2) Given a string, str1, with a size of SIZE, where would you find the delimiter after the user inputs a value that does not exceed the size of the array?
    a. SIZE
    b. SIZE -1
    c. strlen(str1)
    D.None of the above

    I think this one is C, but i thought the delimiter would be after the last value of the string?

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    for #1 you are correct--arrays are passed by reference. the address of the array is passed, not the entire array contents.

    for #2 i would say b. say we have an array of 10 characters (SIZE = 10). we can initialize the 'string' to "hi\0". if you then do strlen(str1) youll get 2, however the array can actually hold 10. writing to index 2 isnt out of bounds, index 10 is out of bounds (SIZE-1 = 9 isnt out of bounds).

    edit:
    Quote Originally Posted by man strlen
    RETURN VALUES

    The strlen() function returns the number of characters that precede the
    terminating NUL character.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    6
    thanks for the help!

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    A and C are the answers, I believe. Looks like you understand it.

Popular pages Recent additions subscribe to a feed