Structures
- What will be the output of the following C code?
#include <stdio.h>
struct student
{
char *ch;
};
void main()
{
struct student m;
struct student *s = &m;
(*s).ch = "Welcome";
printf("%s", m.ch);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Welcome
- What will be the output of the following C code?
#include <stdio.h>
struct Employee
{
char *ch;
};
void main()
{
struct Employee e;
struct Employee *s = &e;
(*s).ch = "Interview Mania";
printf("%p\n%p\n", s, &e);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Same memory address
- What will be the output of the following C code?
#include <stdio.h>
struct calculation1
{
int n[2];
};
struct calculation2
{
int *n;
};
int main()
{
struct calculation1 cal1 = {10, 20};
struct calculation2 *ptr1;
ptr1->n = (struct q*)&cal1.n;
printf("%d\n", ptr1->n[1]);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Segmentation fault
- What will be the output of the following C code?
#include <stdio.h>
struct point1
{
int x[2];
};
struct point2
{
int *x;
};
int main()
{
struct point1 p1 = {11, 22};
struct point2 *ptr1 = (struct q*)&p1;
ptr1->x = (struct q*)&p1.x;
printf("%d\n", ptr1->x[0]);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Undefined behaviour
- What will be the output of the following C code?
#include <stdio.h>
struct output
{
int n1;
int n2;
};
int main()
{
struct output out[] = {11, 21, 13, 41, 15, 61};
struct output *ptr1 = out;
printf("%d %d\n", ptr1->n1, (ptr1 + 2)->n1);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
11 15