1. What is the output of this C code?
-
#include <stdio.h>
-
struct student
-
{
-
char *c;
-
struct student *point;
-
};
-
void main()
-
{
-
struct student s;
-
struct student m;
-
s.c = m.c = "hi";
-
m.point = &s;
-
(m.point)->c = "hey";
-
printf("%st%st", s.c, m.c);
-
}
a) hey hi
b) hi hey
c) Run time error
d) hey hey
Answer
Answer: a [Reason:] None.
2. What is the output of this C code?
-
#include <stdio.h>
-
struct student
-
{
-
char *c;
-
struct student *point;
-
};
-
void main()
-
{
-
struct student s;
-
struct student m;
-
m.point = s;
-
(m.point)->c = "hey";
-
printf("%s", s.c);
-
}
a) Nothing
b) Compile time error
c) hey
d) Varies
Answer
Answer: b [Reason:] None.
3. What is the output of this C code?
-
#include <stdio.h>
-
struct student
-
{
-
char *c;
-
struct student point;
-
};
-
void main()
-
{
-
struct student s;
-
s.c = "hello";
-
printf("%s", s.c);
-
}
a) hello
b) Nothing
c) Varies
d) Compile time error
Answer
Answer: d [Reason:] None.
4. What is the output of this C code?
-
#include <stdio.h>
-
struct student
-
{
-
char *c;
-
struct student *point;
-
};
-
void main()
-
{
-
struct student s;
-
printf("%d", sizeof(s));
-
}
a) 5
b) 9
c) 8
d) 16
Answer
Answer: c [Reason:] None.
5. What is the output of this C code?
-
#include <stdio.h>
-
struct student
-
{
-
char *c;
-
struct student *point;
-
};
-
void main()
-
{
-
struct student s;
-
struct student *m = &s;
-
printf("%d", sizeof(student));
-
}
a) Compile time error
b) 8
c) 5
d) 16
Answer
Answer: a [Reason:] None.
6. What is the output of this C code?
-
#include <stdio.h>
-
struct p
-
{
-
int x;
-
char y;
-
struct p *ptr;
-
};
-
int main()
-
{
-
struct p p = {1, 2, &p};
-
printf("%dn", p.ptr->x);
-
return 0;
-
}
a) Compile time error
b) Undefined behaviour
c) 1
d) 2
Answer
Answer: c [Reason:] None.
7. What is the output of this C code?
-
#include <stdio.h>
-
typedef struct p *q;
-
struct p
-
{
-
int x;
-
char y;
-
q ptr;
-
};
-
typedef struct p *q;
-
int main()
-
{
-
struct p p = {1, 2, &p};
-
printf("%dn", p.ptr->x);
-
return 0;
-
}
a) Compile time error
b) 1
c) Undefined behaviour
d) Address of p
Answer
Answer: a [Reason:] None.
8. Presence of loop in a linked list can be tested by the compiler by.
a) Traveling the list, if NULL is encountered no loop exists
b) Comparing the address of nodes by address of every other node
c) Comparing the the value stored in a node by a value in every other node
d) None of the mentioned
Answer
Answer: b [Reason:] None.