Classical

C Programming MCQ - Structure & Union

11:  

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;


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

 
 

Option: D

Explanation :


12:  

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)

 
 

Option: C

Explanation :


13:  

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

 
 

Option: B

Explanation :


14:  

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); 

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

 
 

Option: D

Explanation :

A bit-fiels need not be named


15:  

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); 

Consider the declaration

    struct wer {
                          unsigned a :  5;
                          unsigned : 0;
                          unsigned b : 3;
                          unsigned : 0;
                          unsigned c : 2 ;
                          unsigned : 0 ;
                          } v;

The storage needed for v is
A.

1 word

B.

2 words

C.

3 words

D.

4 words

 
 

Option: C

Explanation :




Suggest an improvement