WorksheetsMech 3
Total questions: 10
Worksheet time: 8mins
In C, parameters are always
Passed by value
Passed by reference
Non-pointer variables are passed by value and pointers are passed by reference
Passed by value result
Which of the following is true about return type of functions in C?
Functions can return any type
Functions can return any type except array and functions
Functions can return any type except array, functions and union
Functions can return any type except array, functions, function pointer and union
Output of the following function
#include <stdio.h>
int main()
{
printf("%d", main);
return 0;
}
Address of main function
Compiler Error
Runtime Error
Some random value
What will be the output of the following C code?
#include <stdio.h>
int main()
{
char *p = NULL;
char *q = 0;
if (p)
printf(" p ");
else
printf("nullp");
if (q)
printf("q\n");
else
printf(" nullq\n");
}
nullp nullq
Depends on the compiler
x nullq where x can be p or nullp depending on the value of NULL
p q
What will be the output of the following C code?
#include <stdio.h>
int main()
{
void foo(), f(); f();
}
void foo()
{ printf("2 ");
}
void f()
{ printf("1 ");
foo();
}
Compile time error as foo is local to main
1 2
2 1
Compile time error due to declaration of functions inside main
What will be the output of the following C code?
#include <stdio.h>
void foo();
int main()
{
void foo();
foo(); return 0;
}
void foo()
{
printf("2 ");
}
Compile time error
2
Depends on the compiler
Depends on the standard
What is the default return type if it is not specified in function definition?
void
int
double
short int
What will be the output of the following C code?
#include <stdio.h>
void foo(float *);
int main()
{
int i = 10, *p = &i;
foo(&i);
}
void foo(float *p)
{
printf("%f\n", *p);
}
10.000000
0.000000
Compile time error
Undefined behaviour
What will be the output of the following C code?
#include <stdio.h>
int main()
{
int i = 97, *p = &i;
foo(&i);
printf("%d ", *p);
}
void foo(int *p)
{ int j = 2;
p = &j;
printf("%d ", *p);
}
2 97
2 2
Compile time error
Segmentation fault/code crash
Which of the following header declares mathematical functions and macros?
math.h
assert.h
stdmat. h
stdio. h
