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 ); }
Correct Answer
Add the following function prototype in main (): float f ( int, float );
Programming problems
Search Results
1. What would be the output of the following program? main() { float a = 0.7; if ( a < 0.7f ) printf ( " C "); else Printf ( " C++ "); }
3. 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
5. What would be the output of the following program? main() { int i=2 ; printf ("\n%d%d", ++i, ++i ); }
Correct Answer: Output may vary from compiler to compiler The order of evaluation of the arguments to a function call is unspecified
6. 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 "); }
8. 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