1. What is the output of this C code?
-
#include <stdio.h>
-
struct point
-
{
-
int x;
-
int y;
-
};
-
int main()
-
{
-
struct point p = {1};
-
struct point p1 = {1};
-
if(p == p1)
-
printf("equaln");
-
else
-
printf("not equaln");
-
}
a) Compile time error
b) equal
c) depends on the standard
d) not equal
Answer
Answer: a [Reason:] None.
2. What is the output of this C code?
-
#include <stdio.h>
-
struct point
-
{
-
int x;
-
int y;
-
};
-
struct notpoint
-
{
-
int x;
-
int y;
-
};
-
struct point foo();
-
int main()
-
{
-
struct point p = {1};
-
struct notpoint p1 = {2, 3};
-
p1 = foo();
-
printf("%dn", p1.x);
-
}
-
struct point foo()
-
{
-
struct point temp = {1, 2};
-
return temp;
-
}
a) Compile time error
b) 1
c) 2
d) Undefined behaviour
Answer
Answer: a [Reason:] None.
3. What is the output of this C code?
-
#include <stdio.h>
-
struct point
-
{
-
int x;
-
int y;
-
};
-
struct notpoint
-
{
-
int x;
-
int y;
-
};
-
int main()
-
{
-
struct point p = {1};
-
struct notpoint p1 = p;
-
printf("%dn", p1.x);
-
}
a) Compile time error
b) 1
c) 0
d) Undefined
Answer
Answer: a [Reason:] None.
4. What is the output of this C code?
-
#include <stdio.h>
-
struct point
-
{
-
int x;
-
int y;
-
};
-
struct notpoint
-
{
-
int x;
-
int y;
-
};
-
void foo(struct point);
-
int main()
-
{
-
struct notpoint p1 = {1, 2};
-
foo(p1);
-
}
-
void foo(struct point p)
-
{
-
printf("%dn", p.x);
-
}
a) Compile time error
b) 1
c) 0
d) Undefined
Answer
Answer: a [Reason:] None.
5. What is the output of this C code?
-
#include <stdio.h>
-
struct point
-
{
-
int x;
-
int y;
-
};
-
void foo(struct point*);
-
int main()
-
{
-
struct point p1 = {1, 2};
-
foo(&p1);
-
}
-
void foo(struct point *p)
-
{
-
printf("%dn", *p.x++);
-
}
a) Compile time error
b) Segmentation fault/code crash
c) 2
d) 1
Answer
Answer: a [Reason:] None.
6. What is the output of this C code?
-
#include <stdio.h>
-
struct point
-
{
-
int x;
-
int y;
-
};
-
void foo(struct point*);
-
int main()
-
{
-
struct point p1 = {1, 2};
-
foo(&p1);
-
}
-
void foo(struct point *p)
-
{
-
printf("%dn", *p->x++);
-
}
a) Compile time error
b) 1
c) Segmentation fault/code crash
d) 2
Answer
Answer: a [Reason:] None.
7. What is the output of this C code?
-
#include <stdio.h>
-
struct student fun(void)
-
{
-
struct student
-
{
-
char *name;
-
};
-
struct student s;
-
s.name = "alan";
-
return s;
-
}
-
void main()
-
{
-
struct student m = fun();
-
printf("%s", m.name);
-
}
a) Compile time error
b) alan
c) Nothing
d) Varies
Answer
Answer: a [Reason:] None.
8. What is the output of this C code?
-
#include <stdio.h>
-
struct student
-
{
-
char *name;
-
};
-
struct student fun(void)
-
{
-
struct student s;
-
s.name = "alan";
-
return s;
-
}
-
void main()
-
{
-
struct student m = fun();
-
printf("%s", m.name);
-
}
a) Nothing
b) alan
c) Run time error
d) Varies
Answer
Answer: b [Reason:] None.