What is the output of this C code? #include void m() { printf("hi"); } void main() { m(); }
Options
A. hi
B. Run time error
C. None
D. Varies
Correct Answer
hi
Programming problems
Search Results
1. 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
Correct Answer: #include #define MAX 50 void mergeSort(int arr[],int low,int mid,int high); void partition(int arr[],int low,int high); int main(){ int merge[MAX],i,n; printf("Enter the total number of elements: "); scanf("%d",&n); printf("Enter the elements which to be sort: "); for(i=0;imid){ for(k=m;k<=high;k++){ temp[i]=arr[k]; i++; } } else{ for(k=l;k<=mid;k++){ temp[i]=arr[k]; i++; } } for(k=low;k<=high;k++){ arr[k]=temp[k]; } } Sample output: Enter the total number of elements: 5 Enter the elements which to be sort: 2 5 0 9 1 After merge sorting elements are: 0 1 2 5 9
6. The output of the code below is #include int *m() { int *p = 5; return p; } void main() { int *k = m(); printf("%d", k); }
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();
10. Point out the error, if any, in the while loop. main() { int i = 1; while () { printf ( "%d", i++); if (i >10) break ; } }