C Programming - Arrays - Discussion
Discussion Forum : Arrays - Point Out Correct Statements (Q.No. 1)
                   
                                       
                                1.
Which of the following is correct way to define the function fun() in the below program?
 
                                    #include<stdio.h>
int main()
{
    int a[3][4];
    fun(a);
    return 0;
}
Answer: Option
                                                    Explanation:
                                                void fun(int p[][4]){ } is the correct way to write the function fun(). while the others are considered only the function fun() is called by using call by reference.
Discussion:
14 comments Page 1 of 2.
                
                        Yogesh polawar said: 
                         
                        5 years ago
                
                Option C is correct.
                
                        Vandan said: 
                         
                        5 years ago
                
                It is said that when we use "*" in front of the formal parameters it is called function. It represents function is called by reference that means the change of the values of the variables is permanent.
                
                        Sourav said: 
                         
                        8 years ago
                
                According to me, option C is correct.
                
                        Achorite said: 
                         
                        9 years ago
                
                Option C should be the answer.
void fun(int (*p)[][4])
{
}
                void fun(int (*p)[][4])
{
}
                        Dipika More said: 
                         
                        9 years ago
                
                Option A is right and array always passed by reference by default.
                
                        Suraj said: 
                         
                        9 years ago
                
                Here we are sending the base address of 'a'(2d-array). So it should be received by a pointer to 1d-array.
example:
char n[10][20];
input(n);
void input(char (*p)[20])
{
}
                example:
char n[10][20];
input(n);
void input(char (*p)[20])
{
}
                        Harsha vardhan said: 
                         
                        9 years ago
                
                Does fun() means calling any function?
                
                        Fizzz said: 
                         
                        9 years ago
                
                The name of the array "a'' represents the base address. We should be receiving a pointer to a 2D array instead of the array itself.
                
                        Kelvin D said: 
                         
                        10 years ago
                
                According to me, the answer should be option C.
                
                        Shreya said: 
                         
                        1 decade ago
                
                Here passing the address so we should use pointer. Then how first option is correct?
                Post your comments here:
 
            
        Quick links
                            Quantitative Aptitude
                                    
                                    Verbal (English)
                                    
                                    Reasoning
                                    
                                Programming
                                    
                                    Interview
                                    
                                     Placement Papers