Exercise :: Library Functions - Find Output of Program
- Library Functions - General Questions
- Library Functions - Find Output of Program
- Library Functions - Point Out Errors
- Library Functions - True / False Questions
- Library Functions - Yes / No Questions
1. | What will be the output of the program?
|
|||||||
Answer: Option B Explanation: In the program, printf() returns the number of charecters printed on the console
i = printf("How r u\n");
This line prints "How r u" with a new line character and returns the length of string printed then assign it to variable i. i = printf("%d\n", i); In the previous step the value of i is 8. So it prints "8" with a new line character and returns the length of string printed then assign it to variable i. So i = 2 (length of '\n' is 1). printf("%d\n", i); In the previous step the value of i is 2. So it prints "2". |
2. | What will be the output of the program?
|
|||||||
Answer: Option C Explanation: Both ceil() and floor() return the integer found as a double. floor(2.5) returns the largest integral value(round down) that is not greater than 2.5. So output is 2.000000.
ceil(2.5) returns 3, while converting the double to int it returns '0'.
|
3. | What will be the output of the program?
|
|||||||
Answer: Option B Explanation: scanf() returns the number of variables to which you are provding the input.
i = scanf("%d %d", &i, &i); Here Scanf() returns 2. So i = 2. printf("%d\n", i); Here it prints 2. |
4. | What will be the output of the program?
|
|||||||
Answer: Option C Explanation: The ungetc() function pushes the character c back onto the named input stream, which must be open for reading. This character will be returned on the next call to getc or fread for that stream. One character can be pushed back in all situations. A second call to ungetc without a call to getc will force the previous character to be forgotten. |
5. | What will be the output of the program?
|
|||||||
Answer: Option C Explanation:
Function atoi() converts the string to integer.
result1 = result1+atoi(i);
result2 = result2+atof(i); |