Solution:
In C, **“else” is always paired with the nearest unmatched “if”** (no braces rule).
Here:
- The inner `if (array[i] > 0)` is the **nearest unmatched `if`** before `else`.
So, the `else` is paired with the **second (inner)** `if`.
2
For this kind of declaration of main() function in a C program ‘copy.C’:
Solution:
The **argc (argument count)** includes the program name itself.
So the arguments are:
1️⃣ "copy" (program name)
2️⃣ "file1"
3️⃣ "file2"
4️⃣ "file3"
Thus, total arguments = 4.
2
What is the correct file mode that opens preexisting file in read and write mode?
Solution:
- `"r+b"` or `"rb+"` → open **existing file** for both reading and writing (no truncation).
- `"w+b"` or `"wb+"` → open file for reading and writing but **creates/truncates** file.
- `"ab"` → append binary mode.
Hence, the correct mode for **existing file in read-write** is `"r+b"`.
2
Which C expression correctly represents this statement:
“It decrements pointer p before fetching the character that p points to.”
Solution:
- `p--` → post-decrement (use then decrement)
- `--p` → pre-decrement (decrement then use)
Here, we need to **decrement p first**, then fetch the value it points to.
Hence, correct expression: `*--p`
2
How many times this statement will execute:
for (; *s == *t && *t != '\0'; s++, t++)
if both character pointers ‘s’ and ‘t’ point to the same string “abc”.
Solution:
C99 added these new keywords:
- `_Bool`
- `inline`
- `restrict`
- `_Complex`
- `_Imaginary`
`register` is an **old ANSI C keyword**, not added in C99.
Solution:
Valid C versions are:
- C89 (ANSI standard, 1989)
- C90 (ISO standard, 1990)
- C99, C11, C17, and C23
There is **no version called C2007 or CIX**.
4
What will be the output of the statement
printf(3+"goodbye");