A compiler detects Syntax Errors, i.e., grammatical mistakes in code.
3
What will be values for $a$ and $c$ after execution of the following code if $a$ is $10$, $b$ is $5$, and $c$ is $10$?
if ((a > b) && (a <= c))
a = a + 1;
else
c = c + 1;
In C programming, the mode 'a' in the fopen() function is used to open a file in append mode,
which allows new data to be added to the end of the file without deleting existing content.
3
The size of a union is determined by the size of the ________.
Can swap in-place using XOR or +/− without any temp.
3
Consider the following C language declarations & statements.
Which statement is erroneous?
float f1 = 9.9;
float f2 = 66;
const float *ptrF1;
float * const ptrF2 = &f2;
ptrF1 = &f1;
ptrF2++;
ptrF1++;
- `const float *ptrF1;` → pointer to constant float, can move pointer, not modify value.
- `float * const ptrF2 = &f2;` → constant pointer to float, cannot change address, but can modify value.
- Statement `ptrF2++` tries to move a **constant pointer**, which is **not allowed**.
Hence, `ptrF2++` is **erroneous**.
3
What will be output of following statements?
int n1 = 3, n2 = 6, a;
printf("(n1 ^ n2) + (a ^ a) = %d", (n1 ^ n2) + (a ^ a));
Solution:
Operator `^` is **bitwise XOR**.
$n1 = 3 \Rightarrow 011_2$
$n2 = 6 \Rightarrow 110_2$
$n1 \oplus n2 = 101_2 = 5$
Variable `a` is declared but **not initialized**.
Using an uninitialized variable in expression `(a ^ a)` causes **undefined behavior**.
Hence, the program compiles but produces a **run-time error or unpredictable result**.
1
What will be output of following statements?
char ch;
ch = 130;
printf("\nvalue of ch=%d", ch);
Solution:
In C, the range of `char` is from $-128$ to $127$.
When we assign $130$ to a `char`, it overflows:
$130 - 256 = -126$
Thus the value stored in `ch` is $-126$.
Output:
value of ch = -126