1. How is search done in #include and #include “somelibrary.h” according to C standard?
a) When former is used, current directory is searched and when latter is used, standard directory is searched
b) When former is used, standard directory is searched and when latter is used, current directory is searched
c) When former is used, search is done in implementation defined manner and when latter is used, current directory is searched
d) For both, search for ‘somelibrary’ is done in implementation-defined places
2. How is search done in #include and #include”somelibrary.h” normally or conventionally?
a) When former is used, current directory is searched and when latter is used, standard directory is searched
b) When former is used, predefined directory is searched and when latter is used, current directory is searched and then predefined directories are searched
c) When former is used, search is done in implementation defined manner and latter is used to search current directory
d) For both, search for somelibrary is done in implementation-defined manner
3. Can function definition be present in header files?
a) yes
b) no
c) Depends on the compiler
d) Depends on the standard
4. Comment on the output of the following C code.
#include < stdio.h >
#include "test.h"
#include "test.h"
int main()
{
//some code
}
a) true
b) Compile time error
c) false
d) Depends on the compiler
5. What will be the output of the following C code?
#include < stdio.h >
#define foo(m, n) m ## n
void myfunc();
int main()
{
myfunc();
}
void myfunc()
{
printf("%d\n", foo(2, 3));
}
a) 23
b) 2 3
c) Compile time error
d) Undefined behaviour
6. What will be the output of the following C code?
#include < stdio.h >
#define foo(m, n) m ## n
int main()
{
printf("%s\n", foo(k, l));
}
a) k l
b) kl
c) Compile time error
d) Undefined behaviour
7. What will be the output of the following C code?
#include < stdio.h >
#define foo(m, n) " m ## n "
int main()
{
printf("%s\n", foo(k, l));
}
a) k l
b) kl
c) Compile time error
d) m ## n
8. What will be the output of the following C code?
#include < stdio.h >
#define foo(x, y) #x #y
int main()
{
printf("%s\n", foo(k, l));
return 0;
}
a) kl
b) k l
c) xy
d) Compile time error
9. What will be the output of the following C code?
#include < stdio.h >
#define foo(x, y) x / y + x
int main()
{
int i = -6, j = 3;
printf("%d\n",foo(i + j, 3));
return 0;
}
a) Divided by zero exception
b) Compile time error
c) -8
d) -4
10. What will be the output of the following C code?
#include < stdio.h >
void f();
int main()
{
#define foo(x, y) x / y + x
f();
}
void f()
{
printf("%d\n", foo(-3, 3));
}
a) -8
b) -4
c) Compile time error
d) Undefined behaviour