Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

question about local variables and function parameters

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
If you declare a local variable that's a C array, you have to specify the number of elements in the array. On the other hand, if you declare a function parameter that's a C array, you don't have to specify the number of elements. Why the difference?
 
Hi Iemonslice

When you declare a local variable, the compiler must reserve memory for it and so must know what size it is. But when a function receives a variable as an argument, the memory has already been reserved by a calling function and so you don't need to specify the size.

Hope this helps.

CaKiwi
 
while declearing an array your have specify the number of elements because memory will be allocated on that time. But while passing the array your are passing the address of the array and while receiving its just a pointer variable, the required memory for pointer variable is fixed ( 2 or 4 byes).

Maniraja S
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top