Tuesday, September 27, 2005

Structures & Unions

Two Mark Questions

1. Define structure.
Structure is a group of items, in which each is identified by its own identifier. Each item is the member of the structure

2. Explain about memory allocated for structure
The amount of memory, specified by the structure is sum of the storage of each element

3. Define Union
Union is a group of items, which permits variable to be interpreted in several different ways

4. Explain about memory allocated for Union
Compiler allocate sufficient storage to contain the largest member of the union. Only a single member of a union can exits at a single instant. All members of union use the same space, and it can be used by only member at a time.

5. How Structure can be passed to a function?
The structure can be passed to a function, only by passing the address of the structure by means of pointer. P ® X is used to refer to the member X of structure P

6. What are the difference between structure & Union?
Structure: Every member has its own memory space
Union: All members use the same memory space
1) Structure: Can handle all members as required at a time
Union : Can handle only one member at a time
2) Structure: All members can be initialized
Union : Only first member may be initialized
3)Structure: Difference Interpretations for the same memory location is not possible
Union : Different Interpretations for the same memory location are possible
4) Structure: More storage space required
Union : Conservation of memory is possible

Other Questions:

Define Structure. Give example (4)
Explain about Structure with in Structure, how the members can be accessed and give example (6)
Explain array of Structures, how a group of elements in array can be accessed and give example (6)
What are the difference between Structure and Union (5)


Works For You……….

Implements rational number using Structures with numerator and denominator, Write routines to ass, multiply, subtract numbers

Implement complex numbers using structures with real and complex parts. Write routines to add, multiply and negate numbers

Assume integer needs 4 bytes, Float needs 8 bytes, char needs 1 byte.
Struct nametype
{
Char Fname [10];
Char minit;
Char lname [15];
};

Struct person
{
struct nametype name;
int age;
float avgmark;
};

Struct person p[100];

If starting address of P is 100, what are the starting address of
i) P [20];
ii) P [5]. name . minit
iii) P [21]. avgmark