0 votes 0 votes Consider the following program, what will be the output -? #include<stdio.h> int main() { int a[m][n]={{1,2,3},{4,5,6}}; int i,j; for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf("%d ",*(a[j]+i)); } } return 0; } Programming in C programming-in-c output + – Akash Verma 1 asked Aug 22, 2017 edited Jun 16, 2022 by Arjun Akash Verma 1 289 views answer comment Share Follow See 1 comment See all 1 1 comment reply Deepak Kumar 12 commented Aug 22, 2017 reply Follow Share compiler error "error: 'm' and 'n' undeclared (first use in this function)" if ignore then (for ignore the compiler error then do some modification in your code) #include<stdio.h> int main() { int a[3][3]={{1,2,3},{4,5,6}}; int i,j; for(i=0;i<3;i++) { for(j=0;j<2;j++) { printf("%d ",*(a[j]+i)); } } return 0; } output-1 4 2 5 3 6 Explaination- (*a[j]+i) is equal to (*(*(a+j)+i) i=0,j=0 (*(a+0)) points to 1st row *((*(a+0)) +0) point to 1st row -1st element. i=0,j=1 (*(a+1)) points to 2nd row *((*(a+1)) +0) point to 2nd row -1st element. i=1,j=0 (*(a+0)) points to 1st row *((*(a+0)) +1) point to 1st row -2nd element. i=0,j=1 (*(a+1)) points to 2nd row *((*(a+1)) +0) point to 2nd row -2nd element. and so on.. 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes Variable m and n are not declared, So compilation error. vineetydv answered Aug 22, 2017 vineetydv comment Share Follow See all 0 reply Please log in or register to add a comment.
0 votes 0 votes i am assuming the value of m,n be 3,3 respectively so output for the program is 140250360 int main() { int a[3][3]={{1,2,3},{4,5,6}}; int i,j; for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d ",*(a[j]+i)); } } return 0; } sandeepjkh answered Aug 22, 2017 sandeepjkh comment Share Follow See all 0 reply Please log in or register to add a comment.