C Programming

Yes / No Questions

Programming & Coding Exercise Mode

Yes / No Questions

Practice and master this topic with our carefully crafted questions.

4 Questions
6 Minutes
0% Completed
QUEST ? !
Question 1

stderr, stdin, stdout are FILE pointers

A
Yes
B
No
Correct Answer: Option A

Correct Answer: A. Yes

In C, stdin, stdout, and stderr are predefined FILE pointers declared in the <stdio.h> header file.

  • stdin – Standard input stream (usually the keyboard).
  • stdout – Standard output stream (usually the screen/console).
  • stderr – Standard error stream (used for displaying error messages).

These streams are of type FILE * and are automatically opened when a C program starts.

Example:

fprintf(stdout, "Hello\n");
fprintf(stderr, "Error occurred\n");
fscanf(stdin, "%d", &num);
  • A. Yes ✅
    Correct. stdin, stdout, and stderr are predefined FILE * streams.
  • B. No ❌
    Incorrect. They are standard file pointers provided by the C library.

Exam Fact:
The C standard library automatically provides three standard streams: stdin (standard input), stdout (standard output), and stderr (standard error). All three are of type FILE * and are defined in <stdio.h>.

Question 2

A file written in text mode can be read back correctly in binary mode.

A
Yes
B
No
Correct Answer: Option B

Correct Answer: B. No

A file written in text mode cannot always be read back correctly in binary mode.

This is because text mode may perform special character translations depending on the operating system. For example, on Windows:

  • When writing in text mode, the newline character '\n' is stored as the two-character sequence \r\n.
  • When reading in text mode, the sequence \r\n is automatically converted back to '\n'.
  • In binary mode, no such translation takes place; the data is read exactly as it exists in the file.

Therefore, a file written in text mode may not be interpreted correctly if it is later read in binary mode.

  • A. Yes ❌
    Incorrect. Text mode and binary mode handle certain characters differently, so the contents may not be read back correctly.
  • B. No ✅
    Correct. A file written in text mode should generally be read in text mode to ensure proper character translation.

Exam Fact:
Text mode performs character translations (such as \n\r\n on Windows), whereas binary mode reads and writes the exact bytes stored in the file. For this reason, a file should normally be read using the same mode in which it was written.

Question 3

Will the following program work?

#include<stdio.h>

int main()
{
    int n = 5;

    printf("n=%*d\n", n, n);

    return 0;
}
A
Yes
B
No
Correct Answer: Option A

Correct Answer: A. Yes

The program works correctly because the * in the format string specifies that the field width is supplied as an argument.

#include<stdio.h>

int main()
{
    int n = 5;

    printf("n=%*d\n", n, n);

    return 0;
}

In the statement:

printf("n=%*d\n", n, n);
  • The first n (value 5) specifies the field width.
  • The second n (value 5) is the integer to be printed.

Thus, the statement is equivalent to:

printf("n=%5d\n", 5);

The output is:

n=    5

(The number 5 is printed right-aligned in a field width of 5.)

  • A. Yes ✅
    Correct. The * allows the field width to be specified at runtime.
  • B. No ❌
    Incorrect. The program is valid and executes successfully.

Exam Fact:
In printf(), the * in a format specifier indicates that the field width (or precision) is provided as an additional argument. For example, printf("%*d", 5, 10); is equivalent to printf("%5d", 10);.

Question 4

Can we specify a variable filed width in a scanf() format string?

A
Yes
B
No
Correct Answer: Option B

Correct Answer: B. No

In the scanf() function, the field width must be a constant integer specified directly in the format string. Unlike printf(), scanf() does not support using * to specify the field width through a variable.

For example, the following is valid:

char str[20];

scanf("%10s", str);

Here, 10 is a fixed field width specified in the format string.

However, the following is invalid:

int width = 10;

scanf("%*s", width, str);

In scanf(), the * has a different meaning—it is used for assignment suppression, not for specifying a variable field width.

  • A. Yes ❌
    Incorrect. scanf() does not allow the field width to be supplied through a variable.
  • B. No ✅
    Correct. The field width in scanf() must be written as a constant in the format string.

Exam Fact:
The * character has different meanings in printf() and scanf(). In printf(), it specifies a variable field width. In scanf(), it suppresses assignment (e.g., %*d reads but discards an integer).