0% found this document useful (0 votes)
187 views7 pages

MCQ-5 Structure

The document contains 21 multiple choice questions about structures and unions in C programming. Some key points covered are: - Structures allow grouping of different data types into a single type under one name. The members of a structure may be of different types and sizes. - Unions share the same storage location for multiple data types. Only the last member assigned a value will occupy the allocated space. - Bit fields allow defining structure members as collections of bits rather than bytes. They are useful for packing unaligned variable length data. - Pointers to structures allow accessing structure members using pointer notation like ->. Arrays of structures allow defining multiple structured data objects. The questions cover concepts like memory usage

Uploaded by

Catalyst Gaming
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
187 views7 pages

MCQ-5 Structure

The document contains 21 multiple choice questions about structures and unions in C programming. Some key points covered are: - Structures allow grouping of different data types into a single type under one name. The members of a structure may be of different types and sizes. - Unions share the same storage location for multiple data types. Only the last member assigned a value will occupy the allocated space. - Bit fields allow defining structure members as collections of bits rather than bytes. They are useful for packing unaligned variable length data. - Pointers to structures allow accessing structure members using pointer notation like ->. Arrays of structures allow defining multiple structured data objects. The questions cover concepts like memory usage

Uploaded by

Catalyst Gaming
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

Page (1/7)

MCQ-5 Structure

1. Consider the declaration:


static struct
{ unsigned a:5;
unsigned b:5;
unsigned c:5;
unsigned d:5;
}v={1,2,3,4};
v occupies
A. 4 bytes
B. 2 bytes
C. 1 byte
D. None of these

2. A short integer occupies 2 bytes an, ordinary integer 4 bytes and a long
integer occupies 8 bytes of memory
If a structure is defined as
struct TAB{
short a;
int b;
long c;
}TABLE[10];
the the total memory requirement for TABLE is
A. 14
B. 140
C. 40
D. 32

3. Most appropriate sentence to describe unions is


A. Union are like structures
B. Union contain members of different data types which share the same
storage area in memory
C. Union are less frequently used in program
D. Union are used for set operations

4. Which of the following comments about union are true?


A. Union is a structure whose members share the same storage area
B. Size allocated for union is the size of its member needing the maximum
storage
C. Only one of the members of union can be assigned a value at a particular
time
D. All of these
Page (2/7)

5. Consider the following declaration.


struct addr
{
char city[10];
char street[20];
int pincode;
};
struct
{
char name[20];
int sex;
struct addr locate;
} criminal, *kd=&criminal;
sex can be accessed by
A. criminal.sex
B. (*kd).sex
C. kd—>sex
D. All of these

6. Consider the following declaration.


struct addr
{
char city [10];
char street [20];
int pincode;
};
struct
{
char name[20];
int sex;
struct addr locate;
} criminal, *kd=&criminal;
pincode can be accessed by
A. criminal.addr.pincode
B. criminal.pincode
C. kd-->locate.pincode
D. kd.locate —> pincode

7. Consider the following declaration.


struct addr
{
char city [10];
char street [20];
int pincode;
};
struct
Page (3/7)

{
char name[20];
int sex;
struct addr locate;
}criminal, *kd=&criminal;
The third character in the criminal name can be accessed by
A. criminal.name[2]
B. kd—>name[2]
C. ((*kd).name)[2]
D. All of these

8. Consider the following declaration.


struct addr
{
char city[10];
char street[20];
int pincode;
};
struct
{
char name[20];
int sex;
struct addr locate;
} criminal, *kd=&criminal;
*(kd—>name + 2) can be used instead of
A. *(criminal.name + 2)
B. *((*kd).name + 2)
C. Both (a) & (b)
D. either (a) or (b), but not (c)

9. Assuming that bit-fields are accomodated from right to left and word size is
16-bits
Consider the declaration
static struct
{
unsigned a : 5;
unsigned b : 5;
unsigned c : 5;
unsigned d : 5;
} v = (1, 2, 3, 4);
information about d will be in the
A. first word
B. second word
C. in both words
D. none of the above

10. Assuming that bit-fields are accomodated from right to left and word size
Page (4/7)

is 16-bits
Consider the declaration
static struct {
unsigned a : 5;
unsigned b : 5;
unsigned c : 5;
unsigned d : 5;
} v = (1, 2, 3, 4);
If the declaration unsigned c : 5; is replaced by unsigned : 6; then,
A. it results in a syntax error
B. it is meaningless
C. The compiler will give a new name for the field, which can be used in the
program
D. none of the above

11. A bit field is


a) A pointer variable in a structure.
b) One bit or a set of adjacent bits within a word
c) A pointer variable in a union
d) Not used in C

12. Union differs from structure in the following way


a) All members are used at a time
b) Only one member can be used at a time
c) Union cannot have more members
d) Union initialized all members as structure

13. What type of structure is created by the following definition?


struct first { . . . ; struct second *s};
struct second { . . . ; struct first *f};
a) Nested structure
b) Self-referential structure
c) Invalid structure
d) Structured structure

14. the changes made in the members of a structure are available in the
calling function if
a) pointer to structure is passed as argument
b) structure variable is passed
c) the member other then pointer type are passed as argument
d) both option a and c

15. About structure which of the following is true.


1. Structure members are aligned in memory depending on their data type.
2. The size of a structure may not be equal to the sum of the size of its
members.
a) Only option 1
Page (5/7)

b) Only option 2
c) Both option 1 and 2
d) Neither option 1 nor 2

16. struct car


{
int speed;
car type[10];
}vehicle;
struct car *ptr;
ptr = &vehicle;
Referring to the code above, which of the following will make the speed equal
to 200?
a) (*ptr).speed = 200.
b) (*ptr)->speed = 200.
c) *ptr.speed = 200.
d) &ptr.speed = 200.

17. struct date


{
int day;
int month;
int year;
};
main()
{
struct date *d;
....
++d->day; /*statmentN */
....
}
Then the statement statement
a) Increments the pointer to point month
b) Increment the value of day
c) Increment d by sizeof( struct date)
d) None

18. What is the output of the following program?


struct x
{
int a;
long b;
}s;
union y
{
int a;
long b;
Page (6/7)

}u;
print sizeof( s ) and sizeof( u ) if sizeof( int ) = 4 and sizeof( long ) = 4.
a) sizeof( s ) = 8, sizeof( u ) = 4.
b) sizeof( s ) = 4, sizeof( u ) = 4.
c) sizeof( s ) = 4, sizeof( u ) = 8.
d) sizeof( s ) = 8, sizeof( u ) = 8.

19. What is the output of the program?


#include <stdio.h>
main()
{
struct s1 { int i ;};
struct s2 { int i ;};
struct s1 st1;
struct s2 st2;
st1.i = 5;
st2 = st1;
printf(“%d”, st2.i);
}
a) 5
b) 1004
c) Syntax error
d) None

20. For the following declaration


union x {
char ch;
int I;
double j;
} u_var;
What is the value of sizeof( u_var)?
a) Same as sizeof( int )
b) Same as sizeof( double)
c) Same as sizeof( char )
d) None

21. The size of the following union, where an int occupies 4 bytes of memory is
union arc
{
char x;
int y;
char ax[8];
}aha;
a) 16 byte
b) 13 byte
c) 8 byte
d) 4 byte
Page (7/7)

You might also like