51. What will be the output of the following C code?
#include <stdio.h>
struct p
{
int x[2];
};
struct q
{
int *x;
};
int main()
{
struct p p1 = {1, 2};
struct q *ptr1;
ptr1->x = (struct q*)&p1.x;
printf("%d\n", ptr1->x[1]);
}
#include <stdio.h>
struct p
{
int x[2];
};
struct q
{
int *x;
};
int main()
{
struct p p1 = {1, 2};
struct q *ptr1;
ptr1->x = (struct q*)&p1.x;
printf("%d\n", ptr1->x[1]);
}
52. What will be the output of the following C code?
#include <stdio.h>
union p
{
int x;
char y;
}k = {.y = 97};
int main()
{
printf("%d\n", k.y);
}
#include <stdio.h>
union p
{
int x;
char y;
}k = {.y = 97};
int main()
{
printf("%d\n", k.y);
}
53. What will be the output of the following C code?
#include <stdio.h>
struct student
{
char *name;
};
void main()
{
struct student s, m;
s.name = "st";
m = s;
printf("%s%s", s.name, m.name);
}
#include <stdio.h>
struct student
{
char *name;
};
void main()
{
struct student s, m;
s.name = "st";
m = s;
printf("%s%s", s.name, m.name);
}
54. What will be the output of the following C code?
#include <stdio.h>
struct student
{
char *name;
};
struct student s[2], r[2];
void main()
{
s[0].name = "alan";
s[1] = s[0];
r = s;
printf("%s%s", r[0].name, r[1].name);
}
#include <stdio.h>
struct student
{
char *name;
};
struct student s[2], r[2];
void main()
{
s[0].name = "alan";
s[1] = s[0];
r = s;
printf("%s%s", r[0].name, r[1].name);
}
55. What will be the output of the following C code?
#include <stdio.h>
struct point
{
int x;
int y;
};
void foo(struct point*);
int main()
{
struct point p1[] = {1, 2, 3, 4, 5};
foo(p1);
}
void foo(struct point p[])
{
printf("%d %d\n", p->x, p[3].y);
}
#include <stdio.h>
struct point
{
int x;
int y;
};
void foo(struct point*);
int main()
{
struct point p1[] = {1, 2, 3, 4, 5};
foo(p1);
}
void foo(struct point p[])
{
printf("%d %d\n", p->x, p[3].y);
}
56. What will be the output of the following C code?
#include <stdio.h>
void main()
{
char *a[3][3] = {{"hey", "hi", "hello"}, {"his", "her", "hell"}
, {"hellos", "hi's", "hmm"}};
printf("%s", a[1][1]);
}
#include <stdio.h>
void main()
{
char *a[3][3] = {{"hey", "hi", "hello"}, {"his", "her", "hell"}
, {"hellos", "hi's", "hmm"}};
printf("%s", a[1][1]);
}
57. What will be the output of the following C code?
#include <stdio.h>
union u
{
struct
{
unsigned char x : 2;
unsigned int y : 2;
}p;
int x;
};
int main()
{
union u u = {2};
printf("%d\n", u.p.x);
}
#include <stdio.h>
union u
{
struct
{
unsigned char x : 2;
unsigned int y : 2;
}p;
int x;
};
int main()
{
union u u = {2};
printf("%d\n", u.p.x);
}
58. What will be the output of the following C code?
#include <stdio.h>
struct p
{
int k;
char c;
};
int p = 10;
int main()
{
struct p x;
x.k = 10;
printf("%d %d\n", x.k, p);
}
#include <stdio.h>
struct p
{
int k;
char c;
};
int p = 10;
int main()
{
struct p x;
x.k = 10;
printf("%d %d\n", x.k, p);
}
59. What will be the output of the following C code?
#include <stdio.h>
struct p
{
char *name;
struct p *next;
};
struct p *ptrary[10];
int main()
{
struct p p;
p.name = "xyz";
p.next = NULL;
ptrary[0] = &p;
printf("%s\n", ptrary[0]->name);
return 0;
}
#include <stdio.h>
struct p
{
char *name;
struct p *next;
};
struct p *ptrary[10];
int main()
{
struct p p;
p.name = "xyz";
p.next = NULL;
ptrary[0] = &p;
printf("%s\n", ptrary[0]->name);
return 0;
}
60. What will be the output of the following C code?
#include <stdio.h>
struct p
{
char *name;
struct p *next;
};
struct p *ptrary[10];
int main()
{
struct p p;
p->name = "xyz";
p->next = NULL;
ptrary[0] = &p;
printf("%s\n", p->name);
return 0;
}
#include <stdio.h>
struct p
{
char *name;
struct p *next;
};
struct p *ptrary[10];
int main()
{
struct p p;
p->name = "xyz";
p->next = NULL;
ptrary[0] = &p;
printf("%s\n", p->name);
return 0;
}
Read More Section(Structure and Union)
Each Section contains maximum 100 MCQs question on Structure and Union. To get more questions visit other sections.