Monday, August 20, 2012




101. IMP>Can we initialize unions?
Ans: ANSI Standard C allows an initializer for the first member of a union. There is no standard way
of initializing any other member (nor, under a pre-ANSI compiler, is there generally any way of
initializing a union at all).

102. What’s the difference between these two declarations?
Ans: struct x1 { … };
typedef struct { … } x2;
The first form declares a structure tag; the second declares a typedef. The main difference is that the second declaration is of a slightly more abstract type.its users don’t necessarily know that it is a structure, and the keyword struct is not used when declaring instances of it.
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.

0 comments:

Post a Comment