0% found this document useful (0 votes)
38 views6 pages

C9 10Q Structures

Uploaded by

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

C9 10Q Structures

Uploaded by

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

C9_10Q_Structures

1. 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("Specify Subject name");

scanf("%s",s[0].marks.s); //assume subject name English as input

printf("%d %s %s",s[0].marks.m,s[0].marks.s,s[0].name);

}
Answers
1. 65 English Tom
2. 65 Tom
3. Compile Time Error
4. Runtime Error

2. What is the output of this C code?


#include <stdio.h>
struct p
{
int k;
char c;
float f;
};
int main()
{
struct p x = {.c = 166, .f = 3, .k = 1};
printf("%f\n", x.f);
}
Answers
1. 3.000000
2. Compile time error
3. Undefined behavior
4. 1.000000
C9_10Q_Structures

3. What will be the Output?


#include <stdio.h>
struct point
{
int x;
int y;
};
void print(struct point*);
int main()
{
struct point p1[] = {1, 2, 3, 4};
print(p1);
}
void print(struct point p[])
{
printf("%d %d %d %d\n", p->x, ++p->x,p->y,++p->y);
}
Answers
1. 2 2 3 3
2. 1 2 2 3
3. CompileTime Error
4. Runtime Error

4. 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;
u.arr[1] = u.arr[2] = 'E';
printf("%d %c",sizeof(u),u.c);

return 0;
}
Answers
1. 4 A
2. 2 D
3. 3 A
4. 3 D
C9_10Q_Structures

5. 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);
}
void fun(DEMO *d)
{
printf("%d %.2f",d->id,d->price)
}
Answers
1. 22 45.00
2. 11 56.00
3. Compile Time Error
4. printf should be replaced with d[0].id,d[0].price

6. #include <stdio.h>
int main()
{
union values
{
unsigned char a;
unsigned char b;
unsigned int c;
};

union values val;


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
C9_10Q_Structures

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

8. 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)
{
struct test *p = st;
p += 1;
++p->course;
printf(" %s,", p++->course);
printf(" %c,", *++p->course);
printf(" %d,", p[0].capacity);
printf(" %s \n", p->course);

return 0;
}
Answers
1. KDAC Karad , D, 30, DBDA
2. DAC Karad , B, 30, BDA
3. DAC Pune , K, 120, DAC
4. KDAC , K , 120, DAC KARAD
C9_10Q_Structures

9. What will be the output of program?


#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
1. E-DMC 5 E-DESD E-DAC
2. E-DMC 6 JAVA E-DMC
3. E-DESD 8 KARAD E-DESD
4. E-DESD 8 EOS E-DESD

10. What will be the output?

#include<stdio.h>

union demo
{
int a;
int b;

};

int main()
{
union demo d1;
d1.a = 10;
d1.b = 20;
printf("a = %d\n",d1.a);
printf("b = %d\n",d1.b);
printf("size = %d",sizeof(d1));
C9_10Q_Structures

return 0;
}
Answers
1. a = 20 b = 20 size = 4
2. a = 10 b = 20 size = 4
3. a = 10 b = 20 size = 8
4. a = 0 b = 0 size = 8

You might also like