C Structure and Union - placement questions

C Structure and Union - placement questions


1. 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

View Answer / Hide Answer

ANSWER: B




2. 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

View Answer / Hide Answer

ANSWER: B




3. 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

View Answer / Hide Answer

ANSWER: B




4. Identify the wrong syntax

a) typedef struct { member declaration; } NAME; NAME V1, V2;
b) typedef struct tag{ member declaration; } NAME; NAME V1, V2;
c) typedef struct { member declaration; } NAME; NAME V1, V2;
d) typedef struct tag { member declaration; } NAME; NAME V1, V2;

View Answer / Hide Answer

ANSWER: D




5. 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

View Answer / Hide Answer

ANSWER: A




6. 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
b) Only option 2
c) Both option 1 and 2
d) Neither option 1 nor 2

View Answer / Hide Answer

ANSWER: C




7.

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.

View Answer / Hide Answer

ANSWER: A




8.

struct date
{
int day;
int month;
int year;
};
main()
{
struct date *d;
. . . .
++d -> day; /*statmentN */
. . . .
}

Then the statement statmentN

a) Increments the pointer to point month
b) Increment the value of day
c) Increment d by sizeof( struct date)
d) None

View Answer / Hide Answer

ANSWER: B




9. Consider the following structure.

struct numname
{
int no;
char name[25];
};
struct numname n1[] = {
{12, “Raja”},
{15, Selvan},
{18, Prema},
{21, “Naveen”}
};
The output of the following statement would be:
printf(“%d, %d”,n1[2].no, ( *( n1 + 2)).no);

a) 18, ASCII value of p
b) 18, 18
c) 18, ASCII value of r
d) 18, ASCII value of e

View Answer / Hide Answer

ANSWER: B




10. What is the output of the following program?

struct x x
{
int a;
long b;
} s;
union y y
{
int a;
long b;
} 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.

View Answer / Hide Answer

ANSWER: A




11.

struct list
{
int x;
struct list *next;
} *head;
head.x = 100;

Whether the above code is correct or wrong?

a) Use (*head).x = 100
b) Use ( head*).x = 100
c) Use head ->x = 100
d) None

View Answer / Hide Answer

ANSWER: C




12. 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

View Answer / Hide Answer

ANSWER: C




13. 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

View Answer / Hide Answer

ANSWER: B




14. What is the output of the following program?

#include <stdio.h>
typedef struct NType
{
int I;
char c;
long x;
} NewType;
main()
{
NewType *c;
c = ( NewType *) malloc( sizeof(NewType));
c-> = 100;
c->c = ‘C’;
( *c).x = 100L;
printf(“(%d %c %4Ld)”,c->I, c->c, c->x);
}

a) 100 100 100L
b) 100 C 100
c) 100 100 C
d) None

View Answer / Hide Answer

ANSWER: B




15. 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

View Answer / Hide Answer

ANSWER: C




16.

union rainbow
{
int a [5];
float x [5];
};
union rainbow color [20];
void *ptr = color;

Which of the following is the correct way to increment the variable ”ptr” to point to the next member of the array from the sample above?

a) ptr = ptr + sizeof( rainbow.a);
b) ptr = ( void*)((union rainbow*) ptr + 1);
c) ptr = ptr + sizeof( *ptr);
d) ++(int*)ptr;

View Answer / Hide Answer

ANSWER: B




17. What is the size of ptr1 and ptr2?

struct x
{
int j;
char k[ 100];
unsigned I;
};
int *ptr1;
struct x *ptr2;

a) Same depending on the model used
b) 2, 104
c) 2, undefined for memory is not allocated
d) 2, 4

View Answer / Hide Answer

ANSWER: A




18. Which of these are valid declaration?

i) union { int I; int j;};
ii) union u_tag { int I; int j;} u;
iii) union { int I; int j; FILE *K};
iv) union { int I; int j;} u;

a) All are correct
b) Option (i), (ii),and(iv)
c) Option (ii) and (iv)
d) Option (ii)only

View Answer / Hide Answer

ANSWER: C




19.

struct
{
int x;
int y;
}abc;

You cannot access x by the following.

1. abc -> x
2. abc[0] ->x
3. abc.x
4. (abc) ->x

a) Option 1,2 and 4
b) Option 2 and 3
c) Option 1 and 3
d) Option 1,3 and 4

View Answer / Hide Answer

ANSWER: A




20. struct customer *ptr = malloc( sizeof( struct customer));

Given the sample allocation for the pointer ”ptr” found, which statement would be used to reallocate ptr to be an array of 10 element?


a) ptr = realloc( ptr, 10 * sizeof( sizeof customer));
b) ptr = realloc( ptr, 9 * sizeof( struct customer) );
c) realloc(ptr, 9 * sizeof(struct customer));
d) realloc( ptr, 10 * sizeof( struct customer));

View Answer / Hide Answer

ANSWER: A



Post your comment