C Programming - Declarations and Initializations - Discussion


Is there any difference in the following declarations?
int myfun(int arr[]);
int myfun(arr[20]);

[A]. Yes
[B]. No

Answer: Option A


Yes, we have to specify the data type of the parameter when declaring a function.

Sravan said: (Aug 17, 2011)  
What is meant by data type?

Bhaskar said: (Aug 27, 2011)  
First one is Function Declaration that is declared at top of main. So in function declaration we need to specify the type of parameter we are going to pass as actual parameter. Next one is Function calling.

Ankita said: (Mar 21, 2012)  
Can you please explain in which statement data type of parameter is specified and which is the corret statement ?

Kasak said: (Apr 15, 2012)  
First statement is correct
Second statement is incorrect because there is no declaration of data type such as whether is it int, char or double etc?

Karvendan.A.P said: (Aug 22, 2012)  
Can you please tell me exact difference between * and [ ] while passing as an argument like

void my_stringlength(char []);
void my_stringlength(char *);

Hemlata said: (Jun 12, 2014)  
When no data type is declared in arguments passing to function it is taken as int by default so these should be same?

Juhi said: (Mar 31, 2015)  
Is there any difference in the following declarations?

int fun(int arr[]);
int fun(int arr[2]);

Anil T said: (Dec 2, 2015)  

Yes, in case of first, it can accept array of length 1 or more than 1 while in case of second it can accept only array of maximum length 2.

Daniel said: (Oct 5, 2017)  
In C the default return type of a function parameter is int, so the answer for the above statement must be NO.

Venkat said: (Mar 2, 2018)  
Yes, there difference that is;

int myfun(int arr[]);>>>>in this declaration we restrict the compiler you should take parameter as a INT, otherwise send the error.

int myfun(arr[20]);>>>>in this we are not restrict the compiler, compiler choice it is take parameter as any data type.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.