C Quiz – 103

  • Last Updated : 23 Sep, 2021

1
Question 1
For a given integer, which of the following operators can be used to “set” and “reset” a particular bit respectively?
A
| and &
B
&& and ||
C
& and |
D
|| and &&
C Quiz - 103    C Operators    
Discuss it


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;
}
A
=11 15=
B
=11 12=
C
Compiler Error due to (b=a+2) in the first printf().
D
No compile error but output would be =11 X= where X would depend on compiler implementation.
C Quiz - 103    C Functions    
Discuss it


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;
}
A
=11 0=
B
=11 X= where X would depend on Compiler implementation
C
Undefined behavior
D
Compiler Error due to missing argument for second %d
C Quiz - 103    C Functions    
Discuss it


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()?
A
fputs() with FILE stream as stdout.
B
fprintf() with FILE stream as stdout.
C
fwrite() with FILE stream as stdout.
D
All of the above three - a, b and c.
E
In “stdio.h”, there’s no other equivalent function of printf().
C Quiz - 103    C Input and Output    
Discuss it


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
A
None of the above is keywords in C.
B
make main elseif
C
make main
D
auto make
E
sizeof elseif make
C Quiz - 103    C Misc    
Discuss it


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.
1
My Personal Notes arrow_drop_up