Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Arrays & Structures (http://www.go4expert.com/forums/arrays-structures-t13406/)

kanaks_go4ex 30Aug2008 00:06

Arrays & Structures
Can structures be passed to the functions by value?

Why cannot arrays be passed by values to functions?

Please explain.

oogabooga 30Aug2008 20:37

Re: Arrays & Structures
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!

kanaks_go4ex 2Sep2008 00:08

Re: Arrays & Structures
can u give me an example for both the cases.
thanx a lot.

All times are GMT +5.5. The time now is 11:01.