Which bitwise operator is suitable for turning off a particular bit in a number ?
& operator
Clearing a bit means ANDing with a mask that holds 0 in that position and 1 everywhere else, so the operator is the bitwise AND — option 2.
x = x & ~(1 << n);
Why AND is the operator that clears. Look at what AND does to a single bit:
| Bit | Mask | Result |
|---|---|---|
| 0 | 1 | 0 — unchanged |
| 1 | 1 | 1 — unchanged |
| 0 | 0 | 0 — cleared |
| 1 | 0 | 0 — cleared |
A mask bit of 1 leaves the data bit alone; a mask bit of 0 forces it to zero. So a mask of all ones with a single zero clears exactly one bit and preserves the rest — which is the whole requirement.
Building the mask. 1 << n gives a word with only bit n set; the complement operator ~ inverts it to all ones except bit n. To clear bit 3 of a byte: 1 << 3 is 00001000, and ~ makes it 11110111, which ANDed with the data leaves everything except bit 3 untouched.
The complete set of bit manipulations follows the same pattern and is worth holding together:
| Operation | Operator | Idiom |
|---|---|---|
| Clear a bit | & | x &= ~(1<<n) |
| Set a bit | | | x |= (1<<n) |
| Toggle a bit | ^ | x ^= (1<<n) |
| Test a bit | & | if (x & (1<<n)) |
Why the other options fail. The distinction between & and && is the real point of the question. && is the logical AND: it treats each operand as a single true-or-false value and yields 1 or 0, so 12 && 10 is 1, whereas 12 & 10 is 8 — it discards the bit pattern entirely. || is the logical OR, and its bitwise counterpart | would set bits rather than clear them. ! is logical negation, which turns any non-zero value into 0; the bitwise complement is ~.
Where this matters in practice : writing to a port register without disturbing the other pins, masking off status flags, and clearing an interrupt bit — all embedded work where a read-modify-write must touch one bit only.
Hence, the operator is the & operator.
The function "isalnum( )" returns a non-zero value if the character is alphanumeric and zero otherwise. What is header file to be used in the main program ?
To read a integer variable, find the correct format given below :
Int m;
Find the correct list, which is the reverse (at all levels) of the given list :
[[4, 7, 8], 2, 9, [19, 6], 20, 3]
(i) 3, 20
(ii) 9, 2
(iii) [6, 19]
(iv) [8, 7, 4]
Which of the following is not an infinite loop ?
(A) int i = 1;
while (1)
{
i++ ;
}
(B) for ( ; ; ) ;
(C) int t = 0, f ;
while (t)
{
f = 1;
}
(D) int y, x = 0 ;
do
{
y = x;
}
while (x == 0);
The three types of loops available in C language are
i. for
ii. while
iii. do-while
Which loops do not operate without testing the condition even once ?
Match the following :
| List – I | List – II |
| a. associativity | i. memory storage |
| b. # define | ii. if-then-else |
| c. auto | iii. operators with equal precedence |
| d. conditional operator | iv. define operator |
Codes :
Assertion (A) : 'C' uses many data types such as integers (short and long) and float etc.
Reason (R) : Conversion specifier used for short unsigned integer is % lu.
Which storage class is used for the variables that are often required in a program ?
Which is not a proper way of array declaration ?
Exponentiation operation in C is carried out as
Which of the following is NOT a state function or state variable in a thermodynamic system?