Exercise: Questions on C Quiz 7


Questions on C Quiz 7 : Question 1 :
Suppose a, b, c and d are int variables. For ternary operator in C ( ? : ), pick the best statement.

a>b ? : ; is valid statement i.e. 2nd and 3rd operands can be empty and they are implicitly replaced with non-zero value at run-time.
a>b ? c=10 : d=10; is valid statement. Based on the value of a and b, either c or d gets assigned the value of 10.
a>b ? (c=10,d=20) : (c=20,d=10); is valid statement. Based on the value of a and b, either c=10,d=20 gets executed or c=20,d=10 gets executed.
All of the above are valid statements for ternary operator.
Show Answer
Questions on C Quiz 7 : Question 2 :
Which of the followings is correct for a function definition along with storage-class specifier in C language?

int fun(auto int arg)
int fun(static int arg)
int fun(register int arg)
int fun(extern int arg)
All of the above are correct.
Show Answer
Questions on C Quiz 7 : Question 3 :
In a C program snippet, followings are used for definition of Integer variables?
  signed s;
  unsigned u;
  long l;
  long long ll;
Pick the best statement for these.

All of the above variable definitions are incorrect because basic data type int is missing.
All of the above variable definitions are correct because int is implicitly assumed in all of these.
Only “long l;” and “long long ll;” are valid definitions of variables.
Only “unsigned u;” is valid definition of variable.
Show Answer
Questions on C Quiz 7 : Question 4 :
Pick the correct statement for const and volatile.

const is the opposite of volatile and vice versa.
const and volatile can’t be used for struct and union.
const and volatile can’t be used for enum.
const and volatile can’t be used for typedef.
const and volatile are independent i.e. it’s possible that a variable is defined as both const and volatile.
Show Answer
Questions on C Quiz 7 : Question 5 :
For the following declaration of a function in C, pick the best statement
int [] fun(void (*fptr)(int *));

It will result in compile error.
No compile error. fun is a function which takes a function pointer fptr as argument and return an array of int.
No compile error. fun is a function which takes a function pointer fptr as argument and returns an array of int. Also, fptr is a function pointer which takes int pointer as argument and returns void.
No compile error. fun is a function which takes a function pointer fptr as argument and returns an array of int. The array of int depends on the body of fun i.e. what size array is returned. Also, fptr is a function pointer which takes int pointer as argument and returns void.
Show Answer