31. 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};
foo(p1);
}
void foo(struct point p[])
{
printf("%d %d\n", p->x, ++p->x);
}
#include <stdio.h>
struct point
{
int x;
int y;
};
void foo(struct point*);
int main()
{
struct point p1[] = {1, 2, 3, 4};
foo(p1);
}
void foo(struct point p[])
{
printf("%d %d\n", p->x, ++p->x);
}32. What will be the output of the following C code?
#include <stdio.h>
struct p
{
unsigned int x : 2;
unsigned int y : 2;
};
int main()
{
struct p p;
p.x = 3;
p.y = 1;
printf("%d\n", sizeof(p));
}
#include <stdio.h>
struct p
{
unsigned int x : 2;
unsigned int y : 2;
};
int main()
{
struct p p;
p.x = 3;
p.y = 1;
printf("%d\n", sizeof(p));
}33. What type of data is holded by variable u int in the following C code?
#include <stdio.h>
union u_tag
{
int ival;
float fval;
char *sval;
} u;
#include <stdio.h>
union u_tag
{
int ival;
float fval;
char *sval;
} u;34. What will be the output of the following C code?
#include <stdio.h>
typedef struct p
{
int x, y;
};
int main()
{
p k1 = {1, 2};
printf("%d\n", k1.x);
}
#include <stdio.h>
typedef struct p
{
int x, y;
};
int main()
{
p k1 = {1, 2};
printf("%d\n", k1.x);
}35. What will be the output of the following C code according to C99 standard?
#include <stdio.h>
struct p
{
int k;
char c;
float f;
};
int main()
{
struct p x = {.c = 97, .f = 3, .k = 1};
printf("%f\n", x.f);
}
#include <stdio.h>
struct p
{
int k;
char c;
float f;
};
int main()
{
struct p x = {.c = 97, .f = 3, .k = 1};
printf("%f\n", x.f);
}36. What will be the output of the following C code?
#include <stdio.h>
struct p
{
unsigned int x : 2;
unsigned int y : 2;
};
int main()
{
struct p p;
p.x = 3;
p.y = 4;
printf("%d\n", p.y);
}
#include <stdio.h>
struct p
{
unsigned int x : 2;
unsigned int y : 2;
};
int main()
{
struct p p;
p.x = 3;
p.y = 4;
printf("%d\n", p.y);
}37. What will be the output of the following C code?
#include <stdio.h>
void main()
{
int lookup[100] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
printf("%d", lookup[3]);
}
#include <stdio.h>
void main()
{
int lookup[100] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
printf("%d", lookup[3]);
}38. What will be the output of the following C code?
#include <stdio.h>
typedef struct p
{
int x, y;
}k = {1, 2};
int main()
{
p k1 = k;
printf("%d\n", k1.x);
}
#include <stdio.h>
typedef struct p
{
int x, y;
}k = {1, 2};
int main()
{
p k1 = k;
printf("%d\n", k1.x);
}39. What will be the output of the following C code?
#include <stdio.h>
int main()
{
struct p
{
char *name;
struct p *next;
};
struct p *ptrary[10];
struct p p, q;
p.name = "xyz";
p.next = NULL;
ptrary[0] = &p;
q.name = (char*)malloc(sizeof(char)*3);
strcpy(q.name, p.name);
q.next = &q;
ptrary[1] = &q;
printf("%s\n", ptrary[1]->next->next->name);
}
#include <stdio.h>
int main()
{
struct p
{
char *name;
struct p *next;
};
struct p *ptrary[10];
struct p p, q;
p.name = "xyz";
p.next = NULL;
ptrary[0] = &p;
q.name = (char*)malloc(sizeof(char)*3);
strcpy(q.name, p.name);
q.next = &q;
ptrary[1] = &q;
printf("%s\n", ptrary[1]->next->next->name);
}40. Which of the following is not allowed?
Read More Section(Structure and Union)
Each Section contains maximum 100 MCQs question on Structure and Union. To get more questions visit other sections.
