C Functions Test 311) If the integer data type (int) is 2 bytes wide, what is the output of below program?
The correct option is (c). Explanation: The output of the above program will be ef in Windows (Turbo C) and ab in Linux (GCC). Since C is a machine dependent language therefore sizeof(int) may return different values in different operating system. In Windows operating system sizeof(int)=2 bytes. In Linux operating system sizeof(int)=4 bytes. The given size of int is 2 bytes therefore program output is based on the Windows (Turbo C) compiler. Therefore the output of program is ef. 12) Find out the error in the below program?
The correct option is (b). Explanation: The void f() function is not visible to the compiler while going through main() function. Hence we need to declare this prototype void f(); before the main() function. This kind of error is not occurring in modern compiler. Therefore on compiling the above program it give Error: Not allowed assignment. 13) Which statement is correct about the below program?
The correct option is (c). Explanation: In printf statement i.e. printf("%p\n", main()); This statement calls the main() function and then it repeats infinitely, until the stack is overflow. Therefore program runs infinitely without printing anything. 14) Functions can only be called either by value or reference.
The correct option is (a). Explanation: A function can be called either using call by reference or call by value. Therefore the above statement is true. For Example: Call by reference meansc=sub(&x, &y); here the address of x and y are passed. Call by value means c= sub(x, y); here the value of x and y are passed. 15) If two "return" statements are used in a function successively, the compiler will generate warnings.
The correct option is (a). Explanation: Yes, if a function contains two return statements successively then the compiler will generate "Unreachable code" warning in second return statement. For Example: |