wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C Programming Functions and Storage Classes

Total questions: 60

Worksheet time: 20hrs 0mins

Name
Class
Date
1.

What is a function in C programming?

a)

A function is a way to declare a new data type.

b)

A function in C programming is a block of code that performs a specific task and can take inputs and return a value.

c)

A function is a variable that stores data.

d)

A function is a type of loop in C programming.

2.

How do you declare a function in C?

a)

return_type function_name(parameter_type1 parameter_name1, parameter_type2 parameter_name2, ...);

b)

return_type function_name(parameter_name1, parameter_name2)

c)

function return_type(parameter_type1, parameter_type2);

d)

function_name return_type(parameter_name1, parameter_name2);

3.

What is the purpose of the return statement in a function?

a)

To end the function execution immediately.

b)

To define the function's parameters.

c)

To create a loop within the function.

d)

The purpose of the return statement is to provide a value from a function to its caller.

4.

What are the different types of function parameters in C?

a)

Dynamic parameters

b)

Static parameters

c)

Value parameters, Reference parameters, Default parameters

d)

Inline parameters

5.

Explain the difference between call by value and call by reference.

a)

Call by value passes a reference to the variable, while call by reference passes a copy of the variable.

b)

Call by value and call by reference are the same concept.

c)

Call by value modifies the original variable, while call by reference does not.

d)

Call by value passes a copy of the variable, while call by reference passes a reference to the variable.

6.

What is a storage class in C?

a)

A storage class in C specifies the visibility and lifetime of variables and functions.

b)

A storage class in C determines the data type of a variable.

c)

A storage class in C is used for memory allocation only.

d)

A storage class in C defines the syntax of the language.

7.

Name the four storage classes in C.

a)

temporary

b)

local

c)

global

d)

auto, register, static, extern

8.

What is the default storage class for a variable declared inside a function?

a)

auto

b)

extern

c)

register

d)

static

9.

How does the 'static' storage class affect variable lifetime?

a)

The 'static' storage class makes a variable accessible only within its block.

b)

The 'static' storage class causes a variable to be destroyed after each function call.

c)

The 'static' storage class extends the lifetime of a variable to the entire duration of the program.

d)

The 'static' storage class limits the lifetime of a variable to the function scope.

10.

What is the difference between 'auto' and 'register' storage classes?

a)

'auto' is used for global variables, while 'register' is for local variables.

b)

'auto' is a keyword for defining constants, while 'register' is for dynamic memory allocation.

c)

Both 'auto' and 'register' are used for static variables.

d)

The 'auto' storage class is for automatic variables with block scope, while 'register' suggests storing variables in CPU registers for faster access.

11.

How can you define a function that takes another function as an argument?

a)

function myFunction(callback) { callback(1, 2); }

b)

function myFunction() { return; }

c)

function myFunction(callback) { return callback; }

d)

function myFunction(callback) { callback(); }

12.

What is recursion in the context of functions?

a)

Recursion is a method of storing data in a database.

b)

Recursion is a method where a function calls itself to solve smaller instances of the same problem.

c)

Recursion involves using loops to repeat a function's execution.

d)

Recursion is a technique where a function runs in parallel with another function.

13.

How do you handle multiple return values from a function in C?

a)

Use a return statement with a comma-separated list.

b)

Only return values through function parameters.

c)

Use pointers or structures to return multiple values from a function.

d)

Return a single value using a global variable.

14.

What is the significance of function prototypes in C?

a)

Function prototypes are mandatory for all functions in C.

b)

Function prototypes are significant for type checking, enabling forward declarations, and improving code organization.

c)

Function prototypes have no impact on code readability.

d)

Function prototypes are only used for documentation purposes.

15.

Explain the concept of function overloading in C.

a)

Function overloading allows functions to have different names for similar tasks.

b)

Function overloading requires the functions to have the same number of parameters only.

c)

Function overloading in C enables multiple functions with the same name to coexist, distinguished by their parameter types or counts.

d)

Function overloading is a feature exclusive to C++ and not available in C.

16.

What is the role of the 'extern' storage class?

a)

The 'extern' storage class allows variables and functions to be shared across multiple files.

b)

The 'extern' storage class is used for declaring constants in a file.

c)

The 'extern' storage class restricts variable visibility to the current file.

d)

The 'extern' storage class is used to define local variables only.

17.

How can you use a function pointer in C?

a)

Function pointers are used to store variable values.

b)

Function pointers cannot be invoked once assigned.

c)

Function pointers allow you to store the address of a function and invoke it dynamically.

d)

Function pointers can only be used with global functions.

18.

What is the difference between global and local variables?

a)

Global variables are accessible throughout the program; local variables are restricted to their defining function or block.

b)

Global variables are temporary; local variables are permanent.

c)

Local variables can be accessed globally; global variables are limited to their function.

d)

Global variables are only used in loops; local variables can be used anywhere.

19.

How do you define a function that returns a pointer?

a)

int* functionName() { /* function body */ }

b)

void* functionName() { /* function body */ }

c)

char* functionName() { /* function body */ }

d)

int functionName() { /* function body */ }

20.

What are inline functions and when would you use them?

a)

Inline functions cannot be used in recursive calls.

b)

Inline functions are only applicable in object-oriented programming.

c)

Inline functions are used to optimize performance by reducing function call overhead.

d)

Inline functions are used to increase memory usage.

21.

Find the output in following code

int main ()

{

int a,b ;

a= b= 4 ;

b =a++;

Printf ( " %d %d %d %d", a++, --b, ++a, b--);

}

a)

5 3 73

b)

5 4 5 3

c)

6 2 6 4

d)

Syntax Error

22.

Find error/ output in following code

int main ()

{

Static int num = 8;

printf ( " %d" , num = num -2 );

if (num != 0)

main ();

}

a)

8 6 4 2

b)

Infinite output

c)

Invalid because main function can't call it self

d)

6 4 2 0

23.

Find error/ output in following code

How many times " placement Questions" will print.

int main

{

int x;

for ( x=1;x <=10; x++)

{

if ( x < 5)

Continue;

else

break;

Printf (" placement Question ");

{

return 0;

}

a)

Infinite time

b)

11 times

c)

0 time

d)

10 times

24.

Find error/ output in following code

int main ()

{

int a = 10, b = 25;

a = b++ + a++;

b= ++b + ++a;

printf ( " %d %d n", a, b );

}

a)

36 64

b)

35 62

c)

36 63

d)

30 28

25.

Find error/ output in following code

Void fn ()

{

Static int i= 10;

Printf ( " %d " , ++i );

}

int main ()

{

fn();

fn();

}

a)

10 10

b)

11 12

c)

11 11

d)

12 12

26.

Find error/output in following code

int main ()

{

int m = -10,n =20;

n = ( m < 0) ? 0 : 1;

printf ( " %d %d ", m,n ) ;

}

a)

-10 0

b)

10 20

c)

20 -10

d)

0 1

27.

Find error/ output in following code

int main ()

{

int i = 0;

for ( ; ;)

printf ( "%d", i) ;

return 0;

}

a)

O times

b)

Infinite times

c)

10 times

d)

1 times

28.

Find Error/ output in following code

int main ()

{

int x = 1;

While (x= 0)

printf (" Hello");

}

a)

Hello

b)

No output

c)

Infinite time Hello display

d)

Error in code

29.

Find Error/ output in following code

int main ()

{

int x= 0, y= 0;

if ( x > 0)

if ( y >0)

printf ("True");

else

printf ("False");

}

a)

No output

b)

True

c)

False

d)

Error because of dangling else problem

30.

Find Error/ output in following code

Void main ()

{

int a= 1, b= 2, c = 3;

Char d = 0;

if (a,b,c,d)

{

printf ( " EXAM") ;

}

}

a)

No output and No error

b)

EXAM

c)

Runtime Error

d)

Compile time error

31.

Find Error/ output in following code

Void main ()

{

printf ( " % d " , printf ( " computer science"));

}

a)

Computer science16

b)

16computer science

c)

Computer science

d)

Computer science18

32.

What will be the output of the program?

int main ()

{

printf ( 5+"Good Morning\n");

return 0;

}

a)

Good Morning

b)

Good

c)

M

d)

Morning

33.

Are the expression *ptr++ and ++*ptr are the same ?

a)

True

b)

False

34.

Is there any difference between the following two statements?

Char *p = 0;

Char *t = NULL ;

a)

Yes

b)

No

35.

Point out the error in the program

f ( int a, int b)

{

int a;

a = 20;

return a;

}

a)

Missing parentheses in return statement

b)

The function should be defined as int f ( int a, int b)

c)

Redeclaration of a

d)

None of the above

36.

What is the result after execution of the following code if a is 10, b is 5, and c is 10?

if ((a > b) && (a <= c))

a = a + 1;

else

c = c+1;

a)

a = 10, c = 10

b)

a = 11, c = 10

c)

a = 10, c = 11

d)

a = 11, c = 11

37.

Which one of the following is a loop construct that will always be executed once?

a)

for

b)

while

c)

switch

d)

do while

38.

What will the result of 'num' variable after execution of the following statements?

int num = 58;

num % = 11;

a)

3

b)

5

c)

8

d)

11

39.

What will the result of num1 variable after execution of the following statements?

int j = 1, num1 = 4;

while (++j <= 10)

{

num1++;

}

a)

11

b)

12

c)

13

d)

14

40.

Which of the following is not a valid variable name declaration?

a)

int a3;

b)

int 3a;

c)

int _A3;

d)

int a_3

41.

All keywords in C are in ____________

a)

Lowercase

b)

Uppercase

c)

Camelcase

d)

None of these

42.

A translator which reads an entire program written in a high level language and converts it into machine language code is:

a)

Assembler

b)

Compiler

c)

Linker

d)

Loader

43.

The functions printf() and scanf() are defined in which of the following library file:-

a)

math.h

b)

conio.h

c)

stdio.h

d)

stdlib.h

44.

#include <stdio.h>

void main()

{

int k = 4;

float k = 4;

printf("%d", k)

}

A.

a)

4

b)

4.000000

c)

No output

d)

Compile time Error

45.

What will be the output of the following program?

#include <stdio.h>

int main()

{

float c = 5.0;

printf ("Temperature in Fahrenheit is %.2f", (9/5)*c + 32);

return 0;

}

a)

Temperature in Fahrenheit is 41.00

b)

Temperature in Fahrenheit is 37.00

c)

Temperature in Fahrenheit is 0.00

d)

Compiler Error

46.

Who developed C language

a)

Dennis Ritchie

b)

Bill Gates

c)

Dennis Lilly

d)

Stephen

47.

Which is variable declaration?

a)

int a,b;

b)

c=a+b;

c)

printf("%d%d",a,b)

d)

scanf("%d%d",&a,&b);

48.

how to print a and b variable of int and float respectively

a)

scanf("%d%f",&a,&b);

b)

printf("%d%f",a,b);

c)

printf("%f%d",&a,&b);

d)

printf("%f%d",&a,&b);

49.

Which of the following is not logical operator?

a)

&

b)

||

c)

!

d)

&&

50.

int a = 3.5 + 4.5;

a)

a = 0

b)

a = 7

c)

a = 8.0

d)

a = 8

51.

1. What will be the output of the following C code?

a)

Yes

b)

yes default

c)

Undefined behavior

d)

Compile time error

52.

What will be the output of following program?

a)

Hello

b)

OK

c)

Hello

OK

d)

Error

53.

What will be the output of the following C code?

a)

3 2 3

b)

2 2 3

c)

3 2 2

d)

2 3 3

54.

What will be the output of the following C code?

a)

Run time error

b)

7

c)

8

d)

Depends on compiler

55.

What will be the output of the following C code?

a)

Hi is printed 9 times

b)

Hi is printed 8 times

c)

Hi is printed 7 times

d)

Hi is printed 6 times

56.

What will be the output of the following C code?

a)

H

b)

H is printed infinite times

c)

Compile time error

d)

Varies

57.

What will print?

a)

10

b)

20

c)

30

d)

40

58.

Find error/ output in following code

int main ()

{

int i = 0;

for ( ; ;)

printf ( "%d", i) ;

return 0;

}

a)

O times

b)

Infinite times

c)

10 times

d)

1 times

59.

which is the only function all C programs must contain?

a)

start()

b)

sys()

c)

main()

d)

scanf()

60.

Which of the following is not a correct variable type?

a)

float

b)

real

c)

int

d)

double