C Programming Quiz 9 - Structure, Bitfield, Union
C Programming Quiz 9 - Structure, Bitfield, Union
#include<stdio.h>
union test
char ch[2];
};
int main()
ut.num = 325;
return 0;
Answers
1. 32 5
2. 69 5
//3. 69 E
4. 516 E
----------------------------------------------------------------------------------
2. What will be the Output?
#include <stdio.h>
int main()
struct
struct
int m;
char *s;
}marks;
char *name;
}s[3] = {{65,"","Tom"},{75,"","Jerry"},{55,"","Alsa"}};
printf("%d %s %s",s[0].marks.m,s[0].marks.s,s[0].name);
Answers
1. 65 English Tom
2. 65 Tom
#include <stdio.h>
struct p
int k;
char c;
float f;
};
int main()
printf("%f\n", x.f);
Answers
//1. 3.000000
3. Undefined behavior
4. 1.000000
4. What will be the Output?
#include <stdio.h>
struct point
int x;
int y;
};
int main()
print(p1);
Answers
//1. 2 2 3 3
2. 1 2 2 3
3. CompileTime Error
4. Runtime Error
5. What will be the output?
#include<stdio.h>
union
int i;
char c;
char arr[4];
}u;
int main(void)
u.c = 'D';
u.i = 0x0041;
printf("%d %c",sizeof(u),u.c);
return 0;
Answers
//1. 4 A
2. 2 D
3. 3 A
4. 3 D
6. What will be the Output?
#include<stdio.h>
int main()
typedef struct
int id;
float price;
}DEMO;
DEMO d[3]={11,56.00,22,45.00,33,78.00};
fun(d+1);
printf("%d %.2f",d->id,d->price)
Answers
1. 22 45.00
2. 11 56.00
int main()
union values
unsigned char a;
unsigned char b;
unsigned int c;
};
val.a=0;
val.b=0;
val.c=1;
printf("%d,%d,%d",val.a,val.b,val.c);
return 0;
Answers
1. 0,0,1
2. Error
//3. 1,1,1
4. 1,0,0
8. What will be the output of following program ?
#include <stdio.h>
struct sample
int a=1;
char b='S';
float c=11.5;
};
int main()
struct sample s;
printf("%d,%c,%f",s.a,s.b,s.c);
return 0;
Answers
//1. Error
2. 1,S,11.5
3. 1,S,11.500000
4. No Error , No Output
9. What will be the output?
#include <stdio.h>
struct test
int capacity;
char *course;
}st[] = { 220, "DAC Pune", 120, "KDAC Karad ", 30, "DBDA", 60, "DESD", 120, "DMC" };
int main(void)
p += 1;
++p->course;
return 0;
Answers
#include<stdio.h>
int main(void)
struct s
char *p;
int i;
struct s1
char a[4];
char *p;
}o1;
struct s *sp;
}a[] = {"E-DAC",5,"JAVA","PUNE",a+1,
"E-DMC",6,"CPP","PUNE",a+2,
"E-DESD",8,"EOS","KARAD",a},*p;
p = a[2].sp;
printf("%s %d %s %s \n",(p+1)->p,(*p).i,a[1].sp->p,(&2[a])->sp->p);
return 0;
Answers