2. What will be output of following c code? void main() { struct india { char c; float d; }; struct world { int a[3]; char b; struct india orissa; }; struct world st ={{1,2,3},'P','q',1.4}; clrscr(); printf("%dt%ct%ct%f",st.a[1],st.b,st.orissa.c,st.orissa.d); getch(); }
Correct Answer: #include int main() { int a[5][5], b[5][5], c[5][5], i, j, k, sum = 0, m, n, o, p; printf( "\nEnter the row and column of first matrix" ); scanf( "%d %d", &m, &n ); printf( "\nEnter the row and column of second matrix" ); scanf( "%d %d", &o, &p ); if(n!=o) { printf( "Matrix mutiplication is not possible" ); printf( "\nColumn of first matrix must be same as row of second matrix" ); } else { printf( "\nEnter the First matrix" ); for( i=0; i
Correct Answer: #include int main(){ int a[10],i,n,m,c=0,l,u,mid; printf("Enter the size of an array: "); scanf("%d",&n); printf("Enter the elements in ascending order: "); for(i=0;i
6. What would be the output of the following program? main() { extern int i; i = 20; printf( "%d", sizeof(i) ); }
Correct Answer: Here we are initalising the function pointer p to the address of the function fun() But during this initialisation the function has not been defined Hence an error To eliminate this error add the prototype of the fun() before declaration of p, as shown below: extern int fun(); or simply int fun();
9. Point out the error, if any, in the while loop. main() { int i = 1; while () { printf ( "%d", i++); if (i >10) break ; } }
Correct Answer: The condition in the while loop is a must
10. Point out the error, if any, in the following program. main() { int i = 4, j = 2; switch(i) { case 1 : printf (''\n To err is human, to forgive is against company policy."); break; case j : printf (''\n if you have nothing to do, don't do it here."); break; } }