Point out the error, if any, in the following program. main() { int a = 10; void f(); a = f(); printf ( "\n %d", a ); } void f() { printf ( "\n Hi "); }
Correct Answer
In spite of defining the function f() as returning void, the program is trying to collect the value returned by f() in the variable a
Programming problems
Search Results
1. There is a mistake in the following code. Add a statement in it to remove it. main() { int a; a = f (10, 3.14) ; printf ( " %d ", a ); } f (int aa, float bb) { return ( ( float ) aa + bb ); }
4. Which error are you likely to get when you run the following program? main() { struct emp { char name[20]; float sal; }; struct emp e[10]; int i; for ( i = 0 ; i <= 9; i++) scanf ( "%s %f" , e[i].name, &e[i].sal ); }
Correct Answer: The order may vary from compiler to compiler Here the multiplication will happen before the addition , but in which order the functions would be called is undefined In an arithmetic expression the parentheses tell the compiler which operands go with which operators but do not force the compiler to evaluate everything within the parentheses first
6. Will the following function work? f1 ( int a, int b ) { return ( f2 (20) ); } f2 ( int a ) { return ( a * a ); }
7. Indicate what would the SWAP macro be expanded to on preprocessing. Would the code compile? #define SWAP (a, b, c ) (c t; t = a, a = b, b = t; ) main() { int x = 10, y = 20; SWAP (x, y, int ); printf ( " %d%d ", x, y); }
Correct Answer: This is a common error while compiling C program in Linux This error occurs when you are using pthread_create function to create threads in your programs To fix this problem ensure following points: Include header file pthreadh in your program Add ?lpthread linker flag with compilation command 1- Include Header file #include #include 2- Compile command gcc mainc -o main -lpthread
10. In HTML, ___________ tag is used to construct drop-down list boxes and scrolling list boxes.