Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Mech 3

Total questions: 10

Worksheet time: 8mins

Name
Class
Date
1.

In C, parameters are always

a)

Passed by value

b)

Passed by reference

c)

Non-pointer variables are passed by value and pointers are passed by reference

d)

Passed by value result

2.

Which of the following is true about return type of functions in C?

a)

Functions can return any type

b)

Functions can return any type except array and functions

c)

Functions can return any type except array, functions and union

d)

Functions can return any type except array, functions, function pointer and union

3.

Output of the following function

#include <stdio.h>

int main()

{

printf("%d", main);

return 0;

}

a)

Address of main function

b)

Compiler Error

c)

Runtime Error

d)

Some random value

4.

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");

}

a)

nullp nullq

b)

Depends on the compiler

c)

x nullq where x can be p or nullp depending on the value of NULL

d)

p q

5.

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();

}

a)

Compile time error as foo is local to main

b)

1 2

c)

2 1

d)

Compile time error due to declaration of functions inside main

6.

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 ");

}

a)

Compile time error

b)

2

c)

Depends on the compiler

d)

Depends on the standard

7.

What is the default return type if it is not specified in function definition?

a)

void

b)

int

c)

double

d)

short int

8.

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);

}

a)

10.000000

b)

0.000000

c)

Compile time error

d)

Undefined behaviour

9.

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);

}

a)

2 97

b)

2 2

c)

Compile time error

d)

Segmentation fault/code crash

10.

Which of the following header declares mathematical functions and macros?

a)

math.h

b)

assert.h

c)

stdmat. h

d)

stdio. h