Arrays & Structures

Go4Expert Member
30Aug2008,00:06   #1
kanaks_go4ex's Avatar
Can structures be passed to the functions by value?

Why cannot arrays be passed by values to functions?

Please explain.
Ambitious contributor
30Aug2008,20:37   #2
oogabooga's Avatar
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!
Go4Expert Member
2Sep2008,00:08   #3
kanaks_go4ex's Avatar
can u give me an example for both the cases.
thanx a lot.