Input/Output Functions
1.
What is the output of the following C code?
#include <stdio.h>
int main() {
printf("%d", printf("C"));
return 0;
}
A) C
B) C1
C) 1C
D) Compiler Error
✅ Answer: B
Explanation:
The inner printf("C") prints C and returns 1 (number of characters printed).
Then outer printf("%d", 1) prints 1.
Final output: C1.
2.
Which function reads a single character from standard input?
A) scanf()
B) getchar()
C) getch()
D) getche()
✅ Answer: B
Explanation:getchar() is the standard C function that reads one character (and waits for Enter).
3.
Which function returns EOF on end of file or error?
A) getchar()
B) getc()
C) scanf()
D) Both A and B
✅ Answer: D
Explanation:
Both getchar() and getc() return EOF if end of file or read error occurs.
4.
What will the following program print?
#include <stdio.h>
int main() {
char ch;
ch = getchar();
putchar(ch + 2);
return 0;
}
Input: A
A) A
B) C
C) B
D) Compiler Error
✅ Answer: B
Explanation:
Character 'A' ASCII = 65 → 65 + 2 = 67 → 'C'.
5.
Which of the following statements is true?
A) scanf() skips white spaces automatically
B) getchar() skips white spaces automatically
C) getch() is standard C function
D) getche() does not echo input
✅ Answer: A
Explanation:scanf() ignores white spaces by default, while getchar() does not.getch() and getche() are non-standard (conio.h).
6.
Find output:
#include <stdio.h>
int main() {
printf("%5d", 42);
return 0;
}
A) 42
B) 42 (3 spaces before) C) 42 (3 spaces after)
D) 0042
✅ Answer: B
Explanation:%5d prints number in a field of width 5 → right-aligned (3 leading spaces).
7.
What does the putchar() function return?
A) Always 0
B) Character written
C) EOF on error
D) Both B and C
✅ Answer: D
Explanation:putchar() returns the written character on success, or EOF on failure.
8.
Which function is used to read a string including spaces?
A) gets()
B) scanf(“%s”)
C) fgets()
D) getstr()
✅ Answer: C
Explanation:fgets() reads until newline or specified size — includes spaces safely.gets() is unsafe (removed from C11).
9.
What is printed?
#include <stdio.h>
int main() {
printf("%d", printf("Hello"));
}
A) Hello
B) Hello5
C) 5
D) 0
✅ Answer: B
Explanation:
Inner printf("Hello") prints 5 chars → returns 5.
Outer prints “5”.
Output → Hello5.
10.
Which of these format specifiers is incorrect?
A) %d
B) %lf
C) %s
D) %lfd
✅ Answer: D
Explanation:%lfd is invalid — compound format specifiers are not allowed.
11.
Which function reads formatted input from a file?
A) scanf()
B) fscanf()
C) gets()
D) fread()
✅ Answer: B
Explanation:fscanf(FILE*, const char*, ...) reads formatted data from a file stream.
12.
Predict the output:
#include <stdio.h>
int main() {
printf("%c", 'A' + 2);
return 0;
}
A) A
B) B
C) C
D) D
✅ Answer: D
Explanation:'A' + 2 → 65 + 2 = 67 → 'C'
Wait — correction: 65 + 2 = 67 → 'C'. ✅
Answer: C
13.
What will happen if scanf() input format doesn’t match variable type?
A) Undefined behavior
B) Skipped
C) Compiler error
D) Warning only
✅ Answer: A
Explanation:
Runtime mismatch (e.g., %d for float) → undefined behavior or crash.
14.
Which of the following statements is true about printf()?
A) Returns nothing
B) Returns number of characters printed
C) Always returns 0
D) Returns error code
✅ Answer: B
Explanation:printf() returns number of characters successfully printed.
15.
What is the output?
#include <stdio.h>
int main() {
printf("%d", scanf("%d", 10));
}
A) Compiler error
B) Runtime error
C) 1
D) Undefined
✅ Answer: A
Explanation:scanf() expects address → should be &x, not 10.
Constant can’t be modified → compile-time error.
16.
printf("%5.2f", 3.14); will produce:
A) 3.14
B) _3.14 (1 space before)
C) 03.14
D) 3.1400
✅ Answer: B
Explanation:
Width = 5, precision = 2 → total 5 spaces → 1 space before 3.14.
17.
Which function can be used for both reading and writing binary files?
A) fwrite()
B) fread()
C) getc()
D) Both A and B
✅ Answer: D
Explanation:
Both fread() and fwrite() perform binary file I/O.
18.
Which I/O function echoes the input character automatically?
A) getchar()
B) getch()
C) getche()
D) scanf()
✅ Answer: C
Explanation:getche() reads character and displays it on screen immediately.
19.
What does the following print?
#include <stdio.h>
int main() {
printf("%d", putchar('A'));
return 0;
}
A) A
B) A65
C) 65
D) Compiler error
✅ Answer: B
Explanation:putchar('A') prints 'A', returns ASCII 65 → prints A65.
20.
Which statement is true about fgets()?
A) Adds null terminator automatically
B) Stops reading at newline or EOF
C) Reads (n-1) chars at most
D) All of the above
✅ Answer: D
Explanation:fgets(str, n, file) reads max (n-1) chars, includes \n, and terminates with \0.
21.
Identify the output:
#include <stdio.h>
int main() {
printf("%c", getchar());
}
Input: Z
A) Compiler error
B) Z
C) ASCII of Z
D) None
✅ Answer: B
Explanation:getchar() reads a single char from stdin → prints it back.
22.
What will happen if printf() fails?
A) Returns -1
B) Returns EOF
C) Returns 0
D) Crashes program
✅ Answer: B
Explanation:printf() returns EOF (-1) on failure.
23.
What does this code print?
#include <stdio.h>
int main() {
printf("%d", printf("%s", "ABC"));
}
A) ABC
B) ABC3
C) 3
D) CBA
✅ Answer: B
Explanation:
Inner printf prints "ABC" (3 chars), returns 3 → outer prints 3 → ABC3.
24.
Which function is used to read formatted data from a string?
A) scanf()
B) sscanf()
C) gets()
D) fread()
✅ Answer: B
Explanation:sscanf(const char *str, const char *format, …) reads formatted data from a string.
25.
Which is safer alternative to gets()?
A) fgets()
B) scanf()
C) getch()
D) fread()
✅ Answer: A
Explanation:fgets() allows specifying buffer size — prevents overflow.
26.
What will this code output?
#include <stdio.h>
int main() {
int x = 5;
printf("%d %d %d", x, x++, ++x);
return 0;
}
A) 5 6 7
B) 7 6 5
C) Undefined behavior
D) 5 5 5
✅ Answer: C
Explanation:
Order of evaluation of arguments in printf() is unspecified — modifying x multiple times in same statement → undefined behavior.
27.
Which function is used to output a string followed by a newline?
A) puts()
B) printf()
C) fputs()
D) putchar()
✅ Answer: A
Explanation:puts() writes the string and automatically appends a newline \n.
28.
Choose the correct statement about scanf().
A) Returns number of successful inputs
B) Returns EOF on failure
C) Stops scanning at whitespace
D) All of these
✅ Answer: D
Explanation:scanf() returns number of items read; returns EOF if input failure or end-of-file.
29.
Predict the output:
#include <stdio.h>
int main() {
int a;
printf("%d", scanf("%d", &a));
}
Input: 15
A) 0
B) 1
C) 15
D) Compiler error
✅ Answer: B
Explanation:scanf() returns count of successful conversions → prints 1.
30.
Which function writes a character to a specific file stream?
A) putc()
B) putchar()
C) printf()
D) fwrite()
✅ Answer: A
Explanation:putc(char, FILE*) writes a character to a file; putchar() writes to stdout.
31.
What is printed?
#include <stdio.h>
int main() {
printf("%d", putc('X', stdout));
}
A) X
B) 88
C) X88
D) Compiler error
✅ Answer: C
Explanation:putc('X', stdout) prints 'X' and returns its ASCII → 88 → prints X88.
32.
Which function can write formatted data to a string?
A) sprintf()
B) fprintf()
C) snprintf()
D) Both A and C
✅ Answer: D
Explanation:sprintf() and snprintf() write formatted text to a string; the latter is safer (limits length).
33.
Which function reads input from the keyboard without waiting for Enter?
A) getchar()
B) getch()
C) getche()
D) Both B and C
✅ Answer: D
Explanation:getch() and getche() (non-standard, <conio.h>) read instantly — getche() echoes.
34.
What will the following program output?
#include <stdio.h>
int main() {
printf("%s", "GateExam");
return 0;
}
A) GateExam
B) Compiler error
C) Address of string
D) GATEEXAM
✅ Answer: A
Explanation:%s prints null-terminated string directly → “GateExam”.
35.
Which of these functions is not used for character input/output?
A) getchar()
B) putchar()
C) scanf()
D) fread()
✅ Answer: D
Explanation:fread() is binary block I/O, not character-specific.
36.
Which function flushes all output buffers?
A) clearerr()
B) fflush()
C) rewind()
D) fclose()
✅ Answer: B
Explanation:fflush(stdout) writes buffered data to the output immediately.
37.
What happens if you call fflush(stdin)?
A) Clears input buffer (standard behavior)
B) Undefined behavior
C) Always fails
D) Works only in Linux
✅ Answer: B
Explanation:fflush(stdin) is undefined in standard C; some compilers (MSVC) allow it, but portable code shouldn’t use it.
38.
Which of the following reads until newline or EOF?
A) fgets()
B) gets()
C) scanf(“%[^\n]”)
D) All of these
✅ Answer: D
Explanation:
All three stop at newline, but only fgets() is safe.scanf("%[^\n]") reads until newline, too.
39.
What is the output?
#include <stdio.h>
int main() {
int a = 5;
printf("%d", printf("%d", a));
}
A) 55
B) 5
C) 51
D) 15
✅ Answer: A
Explanation:
Inner prints 5 and returns 1. Outer prints 1 → Output = 51.
40.
Which function writes a single character to a file?
A) fprintf()
B) fputc()
C) putchar()
D) fwrite()
✅ Answer: B
Explanation:fputc(c, fp) writes one character to file pointer fp.
41.
Which statement is false about printf()?
A) Uses variable number of arguments
B) Defined in stdio.h
C) Returns number of items read
D) Can print strings
✅ Answer: C
Explanation:printf() prints output → returns count of characters printed, not items read.
42.
What is the output of:
#include <stdio.h>
int main() {
printf("%*d", 5, 25);
}
A) 00025
B) 25 C) 25
D) 25
✅ Answer: B
Explanation:
Dynamic width specifier %*d → 5 spaces total → right-aligned → “___25”.
43.
Which function can position a file pointer?
A) fseek()
B) ftell()
C) rewind()
D) All of these
✅ Answer: D
Explanation:fseek() moves pointer, rewind() resets, and ftell() tells current position.
44.
Which format specifier is used to print address in hexadecimal?
A) %d
B) %p
C) %x
D) %a
✅ Answer: B
Explanation:%p prints pointer value (address) in implementation-defined hex format.
45.
What is printed?
#include <stdio.h>
int main() {
char ch = 'A';
printf("%d", putchar(ch));
}
A) A
B) 65
C) A65
D) Compiler error
✅ Answer: C
Explanation:putchar(ch) prints 'A', returns ASCII 65 → output = A65.
46.
Which function opens a file for both reading and writing?
A) fopen(“file”, “r+”)
B) fopen(“file”, “rw”)
C) fopen(“file”, “r|w”)
D) fopen(“file”, “r&w”)
✅ Answer: A
Explanation:
Mode "r+" opens file for both reading and writing.
47.
What will happen?
#include <stdio.h>
int main() {
printf("%3.1f", 2.678);
}
A) 2.678
B) 2.7
C) 02.6
D) 2.68
✅ Answer: B
Explanation:%.1f rounds to 1 decimal → prints 2.7.
48.
Which of the following correctly reads integer input?
A) scanf(“%d”, a);
B) scanf(“%d”, &a);
C) scanf(“%i”, &a);
D) Both B and C
✅ Answer: D
Explanation:%d or %i both valid for reading integers — need address operator &.
49.
What will this output?
#include <stdio.h>
int main() {
char str[] = "C";
printf("%d", printf("%s", str));
}
A) C
B) C1
C) 1C
D) Compiler error
✅ Answer: B
Explanation:
Inner prints “C” → returns 1 → outer prints 1 → Output = “C1”.
50.
Which function is used to close a file?
A) fclose()
B) endfile()
C) terminate()
D) exit()
✅ Answer: A
Explanation:fclose(FILE *fp) closes an opened file stream and flushes buffer
51.
Which of the following opens a file in append mode for text?
A) fopen("data.txt", "r")
B) fopen("data.txt", "w")
C) fopen("data.txt", "a")
D) fopen("data.txt", "r+")
✅ Answer: C
Explanation:
Mode "a" opens a file for appending — writes always occur at the end of the file.
52.
What does fgetc(fp) return when end of file is reached?
A) NULL
B) EOF
C) 0
D) '\0'
✅ Answer: B
Explanation:fgetc() returns integer EOF (typically −1) when no more characters can be read.
53.
Which of the following is equivalent to getc(fp)?
A) fgetc(fp)
B) getchar()
C) scanf("%c", &ch)
D) All of these
✅ Answer: A
Explanation:getc(fp) and fgetc(fp) behave identically; getchar() reads from stdin.
54.
What is the output of the following?
#include <stdio.h>
int main() {
FILE *fp = fopen("abc.txt", "w");
fprintf(fp, "%d %d", 10, 20);
fclose(fp);
fp = fopen("abc.txt", "r");
int a, b;
fscanf(fp, "%d%d", &a, &b);
printf("%d %d", a, b);
fclose(fp);
}
A) 10 20
B) 20 10
C) Compiler error
D) Garbage values
✅ Answer: A
Explanation:fprintf() writes formatted text; fscanf() reads back same values in sequence.
55.
Which function reads a block of binary data from a file?
A) fgets()
B) fread()
C) fgetc()
D) getchar()
✅ Answer: B
Explanation:fread(ptr, size, count, fp) reads binary data into memory.
56.
fprintf(fp, "GATE %d", 2025);
What does this do?
A) Prints on console
B) Writes to file pointed by fp
C) Writes to both console and file
D) None of the above
✅ Answer: B
Explanation:fprintf() performs formatted output to a file stream, not stdout unless explicitly specified.
57.
Which of the following statements about fopen() is TRUE?
A) Returns integer value
B) Returns file pointer or NULL
C) Requires header <stdlib.h>
D) Creates file only in binary mode
✅ Answer: B
Explanation:fopen() returns FILE* pointer; returns NULL if unable to open file.
58.
What will happen?
#include <stdio.h>
int main() {
FILE *fp = fopen("x.txt", "r");
if (!fp)
printf("Error");
else
fclose(fp);
}
A) Prints “Error” if file missing
B) Runtime error
C) Compiles but infinite loop
D) None
✅ Answer: A
Explanation:fopen("x.txt", "r") fails if file doesn’t exist → returns NULL → prints “Error”.
59.
What is the output?
#include <stdio.h>
int main() {
printf("%d", printf("Hello"));
}
A) 5
B) Hello
C) Hello5
D) Compiler error
✅ Answer: C
Explanation:
Inner printf("Hello") prints “Hello” and returns 5 → Outer prints 5 → Output = “Hello5”.
60.
Which function writes a block of data to a file?
A) fwrite()
B) fputs()
C) fprintf()
D) putc()
✅ Answer: A
Explanation:fwrite(ptr, size, count, fp) writes binary data from memory to file.
61.
What will be the return value of fprintf() if writing fails?
A) Positive integer
B) Negative value
C) EOF
D) 0
✅ Answer: C
Explanation:
If writing error occurs, fprintf() returns EOF.
62.
Which is not a valid file mode in C?
A) “r”
B) “rw”
C) “w+”
D) “a+”
✅ Answer: B
Explanation:"rw" is invalid; C uses separate symbols like "r+", "w+", "a+".
63.
Which of the following functions moves file position to beginning?
A) rewind(fp)
B) fseek(fp, 0, SEEK_SET)
C) Both A and B
D) None
✅ Answer: C
Explanation:
Both rewind() and fseek(fp, 0, SEEK_SET) reset file pointer to start.
64.
What does ftell(fp) return?
A) Current line number
B) Current file position
C) Total file size
D) Bytes remaining
✅ Answer: B
Explanation:ftell() returns current file position in bytes from the start.
65.
What will happen if you call fclose(fp) twice on same pointer?
A) Closes file again
B) Undefined behavior
C) Compilation error
D) Returns EOF
✅ Answer: B
Explanation:
Closing already closed file → undefined behavior.
66.
Which function checks end-of-file indicator?
A) feof()
B) ftell()
C) eof()
D) ferror()
✅ Answer: A
Explanation:feof(FILE *fp) returns non-zero if end-of-file indicator is set.
67.
What is output?
#include <stdio.h>
int main() {
FILE *fp = fopen("temp.txt", "w");
fputs("GateExam", fp);
fclose(fp);
fp = fopen("temp.txt", "r");
char str[10];
fgets(str, 5, fp);
printf("%s", str);
}
A) GateExam
B) Gate
C) GateE
D) Garbled output
✅ Answer: B
Explanation:fgets(str, 5, fp) reads 4 chars + null → “Gate”.
68.
What will be printed?
#include <stdio.h>
int main() {
printf("%5.2f", 12.3456);
}
A) 12.34
B) 12.35
C) 12.3
D) 12.3456
✅ Answer: B
Explanation:%.2f rounds to 2 decimal places → 12.35; width 5 just ensures field spacing.
69.
Which function returns non-zero if file error occurs?
A) ferror()
B) feof()
C) perror()
D) none
✅ Answer: A
Explanation:ferror(fp) detects read/write errors.
70.
What does this code print?
#include <stdio.h>
int main() {
printf("%c", "Gate"[2]);
}
A) a
B) t
C) e
D) G
✅ Answer: B
Explanation:"Gate"[2] = 3rd character = ‘t’.
71.
What happens if fprintf() writes beyond disk space?
A) Data loss only
B) ferror() flag set
C) Continues silently
D) File closes automatically
✅ Answer: B
Explanation:
I/O error sets the ferror() indicator.
72.
What is output?
#include <stdio.h>
int main() {
printf("%d", printf("%s", "C"));
}
A) C1
B) 1C
C) C
D) 1
✅ Answer: A
Explanation:
Inner prints “C” → returns 1 → Outer prints 1 → “C1”.
73.
Which function clears the file error and EOF flags?
A) clearerr()
B) rewind()
C) fclose()
D) fseek()
✅ Answer: A
Explanation:clearerr(fp) resets both file error and EOF indicators.
74.
Which of the following reads formatted data from a string?
A) sscanf()
B) scanf()
C) fscanf()
D) gets()
✅ Answer: A
Explanation:sscanf(str, format, &vars...) parses formatted data from string.
75.
What is output?
#include <stdio.h>
int main() {
printf("%d", printf("%c", 'A'));
}
A) A1
B) 1A
C) 65
D) Compiler error
✅ Answer: A
Explanation:
Inner prints 'A' (1 char) → outer prints 1 → “A1”.
76.
What happens when scanf("%d", a); is used instead of scanf("%d", &a);?
A) Same output
B) Compiler error
C) Segmentation fault (runtime error)
D) Undefined but compiles
✅ Answer: C
Explanation:
Missing & passes wrong address → memory access violation at runtime.
77.
What is the default stream buffer mode for stdout?
A) Unbuffered
B) Line-buffered
C) Fully buffered
D) Depends on OS
✅ Answer: B
Explanation:stdout is line-buffered by default (flushes on newline or fflush).
78.
What is the output?
#include <stdio.h>
int main() {
printf("%-5d", 12);
}
A) 12___
B) ___12
C) 00012
D) 12
✅ Answer: A
Explanation:%-5d → left-align number in width 5 → “12 ”.
79.
Which of the following can write both text and binary files?
A) fprintf()
B) fwrite()
C) Both A and B
D) None
✅ Answer: B
Explanation:fwrite() writes arbitrary binary data; fprintf() only text.
80.
What happens if scanf() encounters mismatch in format specifier?
A) Aborts program
B) Stops reading and returns count of successful items
C) Skips error and continues
D) Undefined behavior
✅ Answer: B
Explanation:scanf() stops at mismatch, returns count of successfully scanned inputs.
81.
What will the following code output?
#include <stdio.h>
int main() {
int a, b;
scanf("%d%d", &a, &b);
printf("%d", a + b);
}
Input:
10
20
A) 1020
B) 30
C) 10
D) 20
✅ Answer: B
Explanation:scanf() ignores whitespace (including newlines).
Reads both integers → 10 + 20 = 30.
82.
What does the following do?
scanf("%*d %d", &a);
A) Reads two integers
B) Reads one integer and ignores the first
C) Reads nothing
D) Causes compilation error
✅ Answer: B
Explanation:* in format specifier → assignment suppression.
Skips the first integer, stores the second.
83.
Which of the following is true about scanf("%[^\n]", str);?
A) Reads till space
B) Reads till tab
C) Reads till newline
D) Reads till EOF only
✅ Answer: C
Explanation:%[^\n] → scans characters until newline (\n) encountered.
84.
What is printed?
#include <stdio.h>
int main() {
char s[20];
scanf("%[A-Z]", s);
printf("%s", s);
}
Input: GATEexam
A) GATEexam
B) GATE
C) G
D) exam
✅ Answer: B
Explanation:%[A-Z] reads only uppercase characters until non-matching input.
85.
What is output?
#include <stdio.h>
int main() {
printf("%d", printf("%s", "GATE"));
}
A) GATE
B) GATE4
C) 4
D) Compiler error
✅ Answer: B
Explanation:
Inner prints “GATE” (4 chars), returns 4 → outer prints 4 → “GATE4”.
86.
Which is not a valid statement about scanf()?
A) Returns count of successful reads
B) Stops reading on whitespace
C) Automatically ignores newline characters
D) Reads entire line including spaces
✅ Answer: D
Explanation:scanf() stops at whitespace by default; does not read entire lines unless %[^\n] used.
87.
What is output?
#include <stdio.h>
int main() {
int x = 10;
printf("%d", printf("%d", x) + printf("%d", x));
}
A) 1010
B) 1020
C) 10102
D) 10102 or undefined
✅ Answer: D
Explanation:
Order of evaluation of function arguments is unspecified → undefined behavior.
88.
What will fseek(fp, 0, SEEK_END); do?
A) Moves to start of file
B) Moves to end of file
C) Clears EOF flag
D) None
✅ Answer: B
Explanation:
Moves file position indicator to end of file (useful to calculate file size with ftell()).
89.
How can you determine total size of file in bytes?
A) ftell(fp)
B) fseek(fp, 0, SEEK_END) followed by ftell(fp)
C) sizeof(fp)
D) length(fp)
✅ Answer: B
Explanation:
Seek to end, then tell → gives total bytes from start to end.
90.
What will be printed?
#include <stdio.h>
int main() {
printf("%d", scanf("%d", &a));
}
Input: 50
A) 50
B) 1
C) 0
D) Error
✅ Answer: B
Explanation:scanf() returns number of successful conversions → prints 1.
91.
Which format specifier reads exactly 5 characters (including spaces)?
A) %s
B) %5s
C) %[5]
D) %c
✅ Answer: B
Explanation:%5s reads up to 5 non-whitespace characters (stops at space or EOF).
92.
Which function writes a string to a file safely?
A) fputs()
B) fprintf()
C) Both A and B
D) puts()
✅ Answer: C
Explanation:
Both fputs(str, fp) and fprintf(fp, "%s", str) can write strings to a file.
93.
Which of these statements about getc() is TRUE?
A) Returns integer value of character
B) Returns EOF at end of file
C) Reads one character from stream
D) All of the above
✅ Answer: D
Explanation:getc(fp) → reads single char, returns as int; returns EOF if no more data.
94.
What happens if you call fread() on a text file opened in “r” mode?
A) Reads binary safely
B) Undefined behavior
C) Works but may interpret newline differently
D) Crashes
✅ Answer: C
Explanation:
Text mode may translate \r\n ↔ \n; use "rb" for exact binary reads.
95.
What is printed?
#include <stdio.h>
int main() {
printf("%10s", "C");
}
A) C
B) “C “
C) ” C”
D) Error
✅ Answer: C
Explanation:
Width specifier 10 → right-aligned string → 9 spaces + ‘C’.
96.
Which function flushes all open output streams?
A) fflush(stdout)
B) fflush(NULL)
C) flushall()
D) None
✅ Answer: B
Explanation:fflush(NULL) flushes all open output buffers.
97.
Which file mode overwrites existing file and writes new data?
A) "w"
B) "a"
C) "r+"
D) "a+"
✅ Answer: A
Explanation:"w" → creates/truncates existing file → starts writing fresh.
98.
What is the difference between puts() and fputs()?
A) puts() adds newline; fputs() doesn’t
B) fputs() adds newline; puts() doesn’t
C) Both add newline
D) Neither adds newline
✅ Answer: A
Explanation:puts() adds a newline automatically, fputs() does not.
99.
What happens here?
#include <stdio.h>
int main() {
printf("%d", printf(""));
}
A) 0
B) Compiler error
C) 1
D) Undefined
✅ Answer: A
Explanation:
Inner printf("") prints nothing → returns 0 → outer prints 0.
100.
What is printed?
#include <stdio.h>
int main() {
FILE *fp = fopen("gate.txt", "w");
fprintf(fp, "%c%c", 'A', 'B');
fclose(fp);
fp = fopen("gate.txt", "r");
printf("%c", fgetc(fp));
fclose(fp);
}
A) B
B) A
C) AB
D) Error
✅ Answer: B
Explanation:
First fprintf() writes “AB”; reopening and reading once prints the first character → ‘A’.