Is it safe to assume that the right-hand side of the ...
C Interview Questions and Answers
(Continued from previous question...)
Is it safe to assume that the right-hand side of the ...
Q; Yes. Idioms like
if(d != 0 && n / d > 0)
{ /* average is greater than 0 */ }
and
if(p == NULL || *p == '\0')
{ /* no string */ }
are quite common in C, and depend on this so-called short-circuiting behavior. In the first example, in the absence of short-circuiting behavior, the right-hand side would divide by 0--and perhaps crash--if d were equal to 0. In the second example, the right-hand side would attempt to reference nonexistent memory--and perhaps crash--if p were a null pointer.
(Continued on next question...)
Other Interview Questions
- String Processing --- Write out a function that prints out all the permutations of a string. For example, abc would give you abc, acb, bac, bca, cab, cba.
- Is there a way to have an array of bits?
- Array is an lvalue or not?
- It is legal in ANSI C
- What will be printed as the result of the operation below ??
- Which bit wise operator is suitable for turning off a particular bit in a number?
- I am trying to use the ANSI stringizing preprocessing operator
- What is the purpose of main( ) function?
- What is the difference between memcpy and memmove?
- String Processing --- Write out a function that prints out all the permutations of a string. For example, abc would give you abc, acb, bac, bca, cab, cba.
- More...
|