Arrays & Structures

Discussion in 'C' started by kanaks_go4ex, Aug 29, 2008.

  1. kanaks_go4ex

    kanaks_go4ex New Member

    Joined:
    Jun 11, 2008
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    0
    Can structures be passed to the functions by value?

    Why cannot arrays be passed by values to functions?

    Please explain.
     
  2. oogabooga

    oogabooga New Member

    Joined:
    Jan 9, 2008
    Messages:
    115
    Likes Received:
    11
    Trophy Points:
    0
    Yes, you can pass a struct by value, but it is rarely done.

    Presumably arrays cannot be passed by value for two reasons:
    1. Arrays can be huge, and since passing by value means
      making a copy of it, it would be very inefficient.
    2. The compiler does not know the size of a dynamic array.
    Actually, you can put a (non-dynamic) array into a struct
    and pass it by value that way!
     
  3. kanaks_go4ex

    kanaks_go4ex New Member

    Joined:
    Jun 11, 2008
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    0
    can u give me an example for both the cases.
    thanx a lot.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice