C Programming

True / False Questions

Programming & Coding Exercise Mode

True / False Questions

Practice and master this topic with our carefully crafted questions.

5 Questions
8 Minutes
0% Completed
QUEST ? !
Question 1

While calling the fprintf() function in the format string conversion specifier %s can be used to write a character string in capital letters.

A
True
B
False
Correct Answer: Option B

Correct Answer: B. False

The fprintf() function is used to write formatted output to a file.

The format specifier %s simply writes a character string exactly as it is stored in memory. It does not convert the string to uppercase or lowercase.

For example:

FILE *fp = fopen("data.txt", "w");

fprintf(fp, "%s", "Hello");

The file will contain:

Hello

It will not automatically become:

HELLO
  • A. True ❌
    Incorrect. The %s conversion specifier does not change the case of characters.
  • B. False ✅
    Correct. %s simply writes the string as it is.

Exam Fact:
The %s format specifier in printf(), fprintf(), and sprintf() prints a null-terminated string exactly as stored. To print a string in uppercase, each character must be converted explicitly using functions such as toupper().

Question 2

A text stream is an ordered sequence of characters composed into lines, each line consisting of zero or more characters plus a terminating new-line character.

A
True
B
False
Correct Answer: Option A

Correct Answer: A. True

A text stream is an ordered sequence of characters organized into lines. According to the C standard, each line consists of:

  • Zero or more characters, followed by
  • A terminating newline character ('\n').

For example, a text file containing:

Hello
Welcome to C
Programming

is treated as a text stream consisting of three lines, where each line ends with a newline character.

  • A. True ✅
    Correct. A text stream is an ordered sequence of characters arranged into lines, with each line ending in a newline character.
  • B. False ❌
    Incorrect. The given statement is the standard definition of a text stream in C.

Exam Fact:
In C, files are generally classified into text files and binary files. A text file stores data as a sequence of characters arranged in lines, while a binary file stores data in its raw binary representation.

Question 3

Offset used in fseek() function call can be a negative number.

A
True
B
False
Correct Answer: Option A

Correct Answer: A. True

The fseek() function is used to move the file position indicator to a specified location within a file.

Its syntax is:

int fseek(FILE *stream, long offset, int origin);

The offset argument can be positive, zero, or negative, depending on the value of origin.

  • SEEK_SET – Offset is measured from the beginning of the file.
  • SEEK_CUR – Offset is measured from the current file position and may be positive or negative.
  • SEEK_END – Offset is measured from the end of the file and is often negative to move backwards.

Example:

fseek(fp, -10L, SEEK_END);

This moves the file pointer 10 bytes backward from the end of the file.

  • A. True ✅
    Correct. The offset parameter of fseek() can be a negative number when moving relative to the current position or the end of the file.
  • B. False ❌
    Incorrect. Negative offsets are valid in many fseek() operations.

Exam Fact:
The offset argument in fseek() is of type long int. A negative offset is commonly used with SEEK_CUR or SEEK_END to move the file pointer backwards.

Question 4

We should not read after a write to a file without an intervening call to fflush(), fseek() or rewind()

A
True
B
False
Correct Answer: Option A

Correct Answer: A. True

When a file is opened in an update mode (such as "r+", "w+", or "a+"), both reading and writing are allowed.

According to the C standard, after performing a write operation, you must call one of the following functions before attempting to read from the same file:

  • fflush() – Flushes the output buffer.
  • fseek() – Repositions the file pointer.
  • rewind() – Moves the file pointer to the beginning of the file.

Without one of these intervening function calls, the behavior of the program is undefined.

Example:

FILE *fp = fopen("data.txt", "w+");

fprintf(fp, "Hello");

/* Required before reading */
fflush(fp);          /* or fseek(fp, 0, SEEK_SET); */

fscanf(fp, "%s", str);
  • A. True ✅
    Correct. After writing to an update stream, an intervening call to fflush(), fseek(), or rewind() is required before reading.
  • B. False ❌
    Incorrect. Reading immediately after writing without one of these function calls results in undefined behavior.

Exam Fact:
For update-mode files (r+, w+, a+), switching between writing and reading requires an intervening call to fflush(), fseek(), fsetpos(), or rewind(). Likewise, switching from reading to writing generally requires a file-positioning function unless the read operation has already encountered EOF.

Question 5

In a call to printf() function the format specifier %b can be used to print binary equivalent of an integer.

A
True
B
False
Correct Answer: Option B

Correct Answer: B. False

The standard C printf() function does not support the format specifier %b.

The commonly used format specifiers in printf() include:

  • %d or %i – Signed decimal integer
  • %u – Unsigned decimal integer
  • %o – Octal integer
  • %x or %X – Hexadecimal integer
  • %c – Character
  • %s – String
  • %f – Floating-point number

There is no standard %b conversion specifier to print the binary equivalent of an integer.

To display a number in binary, you must write your own function or use bitwise operations.

  • A. True ❌
    Incorrect. Standard C does not define %b as a valid format specifier.
  • B. False ✅
    Correct. There is no standard %b format specifier in printf().

Exam Fact:
The standard C library supports format specifiers such as %d, %u, %o, %x, %c, %s, and %f. Binary output is not directly supported by printf() in standard C.