Social Icons

Monday, December 10, 2012

C LANGUAGE INTERVIEW PAPERS ANSWERS & QUESTIONS


103.Why doesn't this code: a[i] = i++; work?
Ans:
The subexpression i++ causes a side effect.it modifies i's value.which leads to undefined
behavior since i is also referenced elsewhere in the same expression.


104.WHy doesn't struct x { ... };
x thestruct;
work?
Ans:
C is not C++. Typedef names are not automatically generated for structure tags.

105.Why can't we compare structures?
Ans:
There is no single, good way for a compiler to implement structure comparison which is consistent
with C's low-level flavor. A simple byte-by-byte comparison could founder on random bits present
in unused ``holes'' in the structure (such padding is used to keep the alignment of later fields
correct). A field-by-field comparison might require unacceptable amounts of repetitive code for
large structures. 


106.How are structure passing and returning implemented?
Ans:
When structures are passed as arguments to functions, the entire structure is typically pushed on
the stack, using as many words as are required. Some compilers merely pass a pointer to the
structure, though they may have to make a local copy to preserve pass-by-value semantics.
Structures are often returned from functions in a location pointed to by an extra,
compiler-supplied ``hidden'' argument to the function. Some older compilers used a special,
static location for structure returns, although this made structure-valued functions
non-reentrant, which ANSI C disallows.

No comments:

Post a Comment