C Language - Structures,Unions

You Are Here :: Home > C Language > Structures,Unions General Questions

 
25.

union test

{
int x;
char arr[4];
int y;
};
int main()
{
union test t;
t.x = 0;
t.arr[1] = 'G';
printf("%s ", t.arr);
return 0;
}
Predict the output of above program. Assume that the size of an integer is 4 bytes and size of character is 1 byte. Also assume that there is no alignment needed.

A. Nothing is printed B. G
C. Garbage character followed by 'G' D. Garbage character followed by 'G', followed by more garbage characters




26.

struct list {

char *item;
struct list *next;
}
/* Here is the main program. */
main(argc, argv)
{ ... }

A. This program doesn't works correctly, but it dumps code after it finishes. B. This program works correctly, but it dumps code after it finishes.
C. output can't be predicted D. None of these




27.

What will be the output of the program ?

#include
int main()
{
union var
{
int a, b;
};
union var v;
v.a=10;
v.b=20;
printf("%d\n", v.a);
return 0;
}

A. 10 B. 20
C. 30 D. 0




28.

What is the output of this C code?

#include
struct student
{
char *name;
};
void main()
{
struct student s, m;
s.name = "st";
m = s;
printf("%s%s", s.name, m.name);
}

A. Compile time error B. Nothing
C. Junk values D. st st




29.

What will be the output of the program ?

#include
int main()
{
enum days {MON=-1, TUE, WED=6, THU, FRI, SAT};
printf("%d, %d, %d, %d, %d, %d\n", MON, TUE, WED, THU, FRI, SAT);
return 0;
}

A. -1, 0, 1, 2, 3, 4 B. -1, 2, 6, 3, 4, 5
C. -1, 0, 6, 2, 3, 4 D. -1, 0, 6, 7, 8, 9




30.

Comment on the following union declaration?

#include
union temp
{
int a;
float b;
char c;
};
union temp s = {1,2.5,'A'}; //REF LINE
Which member of the union will be active after REF LINE?

A. a B. b
C. c D. Such declaration are illegal




« previous

1

2

3

4

5

6

7

8

9

...

next »

 
 
 



© 2013 freshersindia.in ® | Copyrights | Terms & Conditions
   Designed by Freshers India
Catch Us on