You are on page 1of 5

1. What will be the output of the program?

#include<stdio.h> int main() { int i; i = printf("How r u\n"); i = printf("%d\n", i); printf("%d\n", i); return 0; }

How r u A.7 2 How r u C. 1 1


B

How r u B. 8 2 D.Error: cannot assign printf to variable

Answer & Explanation 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. So i = 8 (length of '\n' is 1). 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.
#include<stdio.h> #include<math.h> int main() { float i = 2.5; printf("%f, %d", floor(i), ceil(i)); return 0; }

A.2, 3

B. 2.000000, 3

C. 2.000000, 0
C

D.2, 0

Answer & Explanation 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'. So, the output is '2.000000, 0'.
3. #include <stdio.h> #include <string.h> int main() { char str[30] = "12345678910111213"; printf("The last position of '2' is %d.\n", strrchr(str, '2') - str); return 0; }

4.

What will the function randomize() do in Turbo C under DOS? A.returns a random number. B. returns a random number generator in the specified range. C. returns a random number generator with a random value based on time. D.return a random number with a given seed value.
C

Answer & Explanation Answer: Option C Explanation: The randomize() function initializes the random number generator with a random value based on time. You can try the sample program given below in Turbo-C, it may not work as expected in other compilers.
/* Prints a random number in the range 0 to 99 */

#include <stdlib.h> #include <stdio.h> #include <time.h> int main(void) { randomize(); printf("Random number in the 0-99 range: %d\n", random (100)); return 0; }

5.

1. What will the function rewind() do? A.Reposition the file pointer to a character reverse. B. Reposition the file pointer stream to end of file. C. Reposition the file pointer to begining of that line. D.Reposition the file pointer to begining of file.
D

Answer & Explanation Answer: Option D Explanation: rewind() takes the file pointer to the beginning of the file. so that the next I/O operation will take place at the beginning of the file. Example: rewind(FilePointer);
6.

Input/output function prototypes and macros are defined in which header file? A.conio.h B. stdlib.h C. stdio.h D.dos.h
C

Answer & Explanation Answer: Option C Explanation: stdio.h, which stands for "standard input/output header", is the header in the C standard library that contains macro definitions, constants, and declarations of functions and types used for various standard input and output operations.

7.
#include<stdio.h> float a=3.14; double b=3.14;

A.printf("%f %lf", a, b); B. printf("%Lf %f", a, b); C. printf("%Lf %Lf", a, b); D.printf("%f %Lf", a, b);
A

Answer & Explanation Answer: Option A Explanation: To print a float value, %f is used as format specifier. To print a double value, %lf is used as format specifier. Therefore, the answer is printf("%f %lf", a, b);
8.

Which files will get closed through the fclose() in the following program?
#include<stdio.h> int main() { FILE *fs, *ft, *fp; fp = fopen("A.C", "r"); fs = fopen("B.C", "r"); ft = fopen("C.C", "r"); fclose(fp, fs, ft); return 0; }

A."A.C" "B.C" "C.C" C. "A.C"


D

B. "B.C" "C.C" D.Error in fclose()

Answer & Explanation Answer: Option D

Explanation: Extra parameter in call to fclose().

You might also like