C Programming - Arrays - Discussion
Discussion Forum : Arrays - Yes / No Questions (Q.No. 3)
3.
Is there any difference int the following declarations?
int fun(int arr[]);
int fun(int arr[2]);
int fun(int arr[]);
int fun(int arr[2]);
Answer: Option
Explanation:
No, both the statements are same. It is the prototype for the function fun() that accepts one integer array as an parameter and returns an integer value.
Discussion:
14 comments Page 2 of 2.
MrMin said:
10 years ago
Types of pointers to these functions will vary, So you these declarations are NOT the same. Also, you can't do.
int func1 (int array [], int some_other);
But you can do int func2 (int array [2], int some_other);
That's because at lowest level the compiler needs to know where some_other argument lies on the call stack. With the first declaration it can't determine it in most cases.
int func1 (int array [], int some_other);
But you can do int func2 (int array [2], int some_other);
That's because at lowest level the compiler needs to know where some_other argument lies on the call stack. With the first declaration it can't determine it in most cases.
Raj said:
9 years ago
1st one does not contain size of the array.
2nd one contain size of array.
2nd one contain size of array.
Rohit Singh said:
9 years ago
You are right @Ravindra Bagale.
Anomi said:
8 years ago
In fact, they are same, representing variable array but the second alerts people it's a fixed-size array.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers