C Quiz – 103

Question 1
For a given integer, which of the following operators can be used to “set” and “reset” a particular bit respectively?
Tick
| and &
Cross
&& and ||
Cross
& and |
Cross
|| and &&


Question 1-Explanation: 
Bitwise operator | can be used to “set” a particular bit while bitwise operator & can be used to “reset” a particular bit. Please note that && and || are logical operators which evaluate their operands to logical TRUE or FALSE. It should be noted that bitwise operator & can be used for checking a particular bit also i.e. whether a bit is set or not. So correct answer it A.
Question 2
What’s going to happen when we compile and run the following C program snippet?
#include "stdio.h"
int main()
{
 int a = 10;
 int b = 15;

 printf("=%d",(a+1),(b=a+2));
 printf(" %d=",b);

 return 0;
}
Cross
=11 15=
Tick
=11 12=
Cross
Compiler Error due to (b=a+2) in the first printf().
Cross
No compile error but output would be =11 X= where X would depend on compiler implementation.


Question 2-Explanation: 
As per C standard C11, all the arguments of printf() are evaluated irrespective of whether they get printed or not. That’s why (b=a+2) would also be evaluated and value of b would be 12 after first printf(). That’s why correct answer is B.
Question 3
What’s going to happen when we compile and run the following C program snippet?
#include "stdio.h"
int main()
{
 int a = 10;

 printf("=%d %d=",(a+1));

 return 0;
}
Cross
=11 0=
Cross
=11 X= where X would depend on Compiler implementation
Tick
Undefined behavior
Cross
Compiler Error due to missing argument for second %d


Question 3-Explanation: 
In the context of printf() and fprintf(), as per C standard C11 clause 7.21.6.1, \"If there are insufficient arguments for the format, the behavior is undefined. If the format is exhausted while arguments remain, the excess arguments are evaluated (as always) but are otherwise ignored.\" Some implementation can choose to print =10 0= while other implementations can choose to print =11 X=. That\'s why the output of above program varies depending on the compiler and platform. Hence, correct answer is C).
Question 4
Which of the following functions from “stdio.h” can be used in place of printf()?
Cross
fputs() with FILE stream as stdout.
Tick
fprintf() with FILE stream as stdout.
Cross
fwrite() with FILE stream as stdout.
Cross
All of the above three - a, b and c.
Cross
In “stdio.h”, there’s no other equivalent function of printf().


Question 4-Explanation: 
Though fputs() and fwrite() can accept FILE stream stdout and can output the given string but the input string wouldn’t result in formatted (i.e. containing format specifiers) output. But fprintf() can be used for formatted output. That’s why fprintf(stdout,\"=%d=\",a); and printf(\"=%d=\",a); both are equivalent. The correct answer is B.
Question 5

As per C language standard, which of the followings is/are not keyword(s)? Pick the best statement. auto make main sizeof elseif

Cross

sizeof elseif make

Tick

make main elseif

Cross

make main

Cross

auto make

Cross

None of the above is keywords in C.



Question 5-Explanation: 

\"auto\" is a storage specifier defined in C language. \"sizeof\" is unary operator defined in C language. Both of these are reserved words i.e. keywords as per C language standard. All the other 3 i.e. main make and elseif aren\'t keywords. In fact, you can use int main, make, elseif; in your C program.

There are 5 questions to complete.

  • Last Updated : 26 Sep, 2023

Share your thoughts in the comments
Similar Reads