C Programming - Arrays - Discussion
Discussion Forum : Arrays - Find Output of Program (Q.No. 2)
                   
                                       
                                2.
What will be the output of the program ?
 
                                    #include<stdio.h>
int main()
{
    static int a[2][2] = {1, 2, 3, 4};
    int i, j;
    static int *p[] = {(int*)a, (int*)a+1, (int*)a+2};
    for(i=0; i<2; i++)
    {
        for(j=0; j<2; j++)
        {
            printf("%d, %d, %d, %d\n", *(*(p+i)+j), *(*(j+p)+i), 
                                    *(*(i+p)+j), *(*(p+j)+i));
        }
    }
    return 0;
}
Discussion:
78 comments Page 2 of 8.
                
                        Raadhi said: 
                         
                        8 years ago
                
                Thank you @Dilip.
                
                        Raadhi said: 
                         
                        8 years ago
                
                Thank you @Dilip.
                
                        Raadhi said: 
                         
                        8 years ago
                
                Thank you @Dilip.
                
                        Som said: 
                         
                        8 years ago
                
                Hi,
If the variable 'p' in printf statement is replaced by array name 'a', then we get the output as option 'A'.
Could anyone explain this discrepancy?
                If the variable 'p' in printf statement is replaced by array name 'a', then we get the output as option 'A'.
Could anyone explain this discrepancy?
                        Arunsethupathy said: 
                         
                        8 years ago
                
                Thank You @Shweta.
                
                        Preethi said: 
                         
                        8 years ago
                
                Nice Explanation @Dilip.
                
                        Manoja V. said: 
                         
                        8 years ago
                
                Thank you @Dilip.
                
                        Nikhil said: 
                         
                        8 years ago
                
                Please explain this question how the compiler works?
                
                        Pradeepa said: 
                         
                        8 years ago
                
                Please, anybody explain this concept and tell the answer for it.
#include
void main()
{
int a[2][2]={{2},{3}};
printf("%d",a[0][0]);
printf("%d",a[0][1]);
printf("%d",a[1][0]);
printf("%d",a[1][1]);
}
                #include
void main()
{
int a[2][2]={{2},{3}};
printf("%d",a[0][0]);
printf("%d",a[0][1]);
printf("%d",a[1][0]);
printf("%d",a[1][1]);
}
                        Priyal said: 
                         
                        8 years ago
                
                Thank you for you answer @Dilip.
                Post your comments here:
 
            
        Quick links
                            Quantitative Aptitude
                                    
                                    Verbal (English)
                                    
                                    Reasoning
                                    
                                Programming
                                    
                                    Interview
                                    
                                     Placement Papers