WorksheetsC Programming Functions and Storage Classes
Total questions: 60
Worksheet time: 20hrs 0mins
What is a function in C programming?
A function is a way to declare a new data type.
A function in C programming is a block of code that performs a specific task and can take inputs and return a value.
A function is a variable that stores data.
A function is a type of loop in C programming.
How do you declare a function in C?
return_type function_name(parameter_type1 parameter_name1, parameter_type2 parameter_name2, ...);
return_type function_name(parameter_name1, parameter_name2)
function return_type(parameter_type1, parameter_type2);
function_name return_type(parameter_name1, parameter_name2);
What is the purpose of the return statement in a function?
To end the function execution immediately.
To define the function's parameters.
To create a loop within the function.
The purpose of the return statement is to provide a value from a function to its caller.
What are the different types of function parameters in C?
Dynamic parameters
Static parameters
Value parameters, Reference parameters, Default parameters
Inline parameters
Explain the difference between call by value and call by reference.
Call by value passes a reference to the variable, while call by reference passes a copy of the variable.
Call by value and call by reference are the same concept.
Call by value modifies the original variable, while call by reference does not.
Call by value passes a copy of the variable, while call by reference passes a reference to the variable.
What is a storage class in C?
A storage class in C specifies the visibility and lifetime of variables and functions.
A storage class in C determines the data type of a variable.
A storage class in C is used for memory allocation only.
A storage class in C defines the syntax of the language.
Name the four storage classes in C.
temporary
local
global
auto, register, static, extern
What is the default storage class for a variable declared inside a function?
auto
extern
register
static
How does the 'static' storage class affect variable lifetime?
The 'static' storage class makes a variable accessible only within its block.
The 'static' storage class causes a variable to be destroyed after each function call.
The 'static' storage class extends the lifetime of a variable to the entire duration of the program.
The 'static' storage class limits the lifetime of a variable to the function scope.
What is the difference between 'auto' and 'register' storage classes?
'auto' is used for global variables, while 'register' is for local variables.
'auto' is a keyword for defining constants, while 'register' is for dynamic memory allocation.
Both 'auto' and 'register' are used for static variables.
The 'auto' storage class is for automatic variables with block scope, while 'register' suggests storing variables in CPU registers for faster access.
How can you define a function that takes another function as an argument?
function myFunction(callback) { callback(1, 2); }
function myFunction() { return; }
function myFunction(callback) { return callback; }
function myFunction(callback) { callback(); }
What is recursion in the context of functions?
Recursion is a method of storing data in a database.
Recursion is a method where a function calls itself to solve smaller instances of the same problem.
Recursion involves using loops to repeat a function's execution.
Recursion is a technique where a function runs in parallel with another function.
How do you handle multiple return values from a function in C?
Use a return statement with a comma-separated list.
Only return values through function parameters.
Use pointers or structures to return multiple values from a function.
Return a single value using a global variable.
What is the significance of function prototypes in C?
Function prototypes are mandatory for all functions in C.
Function prototypes are significant for type checking, enabling forward declarations, and improving code organization.
Function prototypes have no impact on code readability.
Function prototypes are only used for documentation purposes.
Explain the concept of function overloading in C.
Function overloading allows functions to have different names for similar tasks.
Function overloading requires the functions to have the same number of parameters only.
Function overloading in C enables multiple functions with the same name to coexist, distinguished by their parameter types or counts.
Function overloading is a feature exclusive to C++ and not available in C.
What is the role of the 'extern' storage class?
The 'extern' storage class allows variables and functions to be shared across multiple files.
The 'extern' storage class is used for declaring constants in a file.
The 'extern' storage class restricts variable visibility to the current file.
The 'extern' storage class is used to define local variables only.
How can you use a function pointer in C?
Function pointers are used to store variable values.
Function pointers cannot be invoked once assigned.
Function pointers allow you to store the address of a function and invoke it dynamically.
Function pointers can only be used with global functions.
What is the difference between global and local variables?
Global variables are accessible throughout the program; local variables are restricted to their defining function or block.
Global variables are temporary; local variables are permanent.
Local variables can be accessed globally; global variables are limited to their function.
Global variables are only used in loops; local variables can be used anywhere.
How do you define a function that returns a pointer?
int* functionName() { /* function body */ }
void* functionName() { /* function body */ }
char* functionName() { /* function body */ }
int functionName() { /* function body */ }
What are inline functions and when would you use them?
Inline functions cannot be used in recursive calls.
Inline functions are only applicable in object-oriented programming.
Inline functions are used to optimize performance by reducing function call overhead.
Inline functions are used to increase memory usage.
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--);
}
5 3 73
5 4 5 3
6 2 6 4
Syntax Error
Find error/ output in following code
int main ()
{
Static int num = 8;
printf ( " %d" , num = num -2 );
if (num != 0)
main ();
}
8 6 4 2
Infinite output
Invalid because main function can't call it self
6 4 2 0
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;
}
Infinite time
11 times
0 time
10 times
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 );
}
36 64
35 62
36 63
30 28
Find error/ output in following code
Void fn ()
{
Static int i= 10;
Printf ( " %d " , ++i );
}
int main ()
{
fn();
fn();
}
10 10
11 12
11 11
12 12
Find error/output in following code
int main ()
{
int m = -10,n =20;
n = ( m < 0) ? 0 : 1;
printf ( " %d %d ", m,n ) ;
}
-10 0
10 20
20 -10
0 1
Find error/ output in following code
int main ()
{
int i = 0;
for ( ; ;)
printf ( "%d", i) ;
return 0;
}
O times
Infinite times
10 times
1 times
Find Error/ output in following code
int main ()
{
int x = 1;
While (x= 0)
printf (" Hello");
}
Hello
No output
Infinite time Hello display
Error in code
Find Error/ output in following code
int main ()
{
int x= 0, y= 0;
if ( x > 0)
if ( y >0)
printf ("True");
else
printf ("False");
}
No output
True
False
Error because of dangling else problem
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") ;
}
}
No output and No error
EXAM
Runtime Error
Compile time error
Find Error/ output in following code
Void main ()
{
printf ( " % d " , printf ( " computer science"));
}
Computer science16
16computer science
Computer science
Computer science18
What will be the output of the program?
int main ()
{
printf ( 5+"Good Morning\n");
return 0;
}
Good Morning
Good
M
Morning
Are the expression *ptr++ and ++*ptr are the same ?
True
False
Is there any difference between the following two statements?
Char *p = 0;
Char *t = NULL ;
Yes
No
Point out the error in the program
f ( int a, int b)
{
int a;
a = 20;
return a;
}
Missing parentheses in return statement
The function should be defined as int f ( int a, int b)
Redeclaration of a
None of the above
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 = 10, c = 10
a = 11, c = 10
a = 10, c = 11
a = 11, c = 11
Which one of the following is a loop construct that will always be executed once?
for
while
switch
do while
What will the result of 'num' variable after execution of the following statements?
int num = 58;
num % = 11;
3
5
8
11
What will the result of num1 variable after execution of the following statements?
int j = 1, num1 = 4;
while (++j <= 10)
{
num1++;
}
11
12
13
14
Which of the following is not a valid variable name declaration?
int a3;
int 3a;
int _A3;
int a_3
All keywords in C are in ____________
Lowercase
Uppercase
Camelcase
None of these
A translator which reads an entire program written in a high level language and converts it into machine language code is:
Assembler
Compiler
Linker
Loader
The functions printf() and scanf() are defined in which of the following library file:-
math.h
conio.h
stdio.h
stdlib.h
#include <stdio.h>
void main()
{
int k = 4;
float k = 4;
printf("%d", k)
}
A.
4
4.000000
No output
Compile time Error
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;
}
Temperature in Fahrenheit is 41.00
Temperature in Fahrenheit is 37.00
Temperature in Fahrenheit is 0.00
Compiler Error
Who developed C language
Dennis Ritchie
Bill Gates
Dennis Lilly
Stephen
Which is variable declaration?
int a,b;
c=a+b;
printf("%d%d",a,b)
scanf("%d%d",&a,&b);
how to print a and b variable of int and float respectively
scanf("%d%f",&a,&b);
printf("%d%f",a,b);
printf("%f%d",&a,&b);
printf("%f%d",&a,&b);
Which of the following is not logical operator?
&
||
!
&&
int a = 3.5 + 4.5;
a = 0
a = 7
a = 8.0
a = 8
1. What will be the output of the following C code?
Yes
yes default
Undefined behavior
Compile time error
What will be the output of following program?
Hello
OK
Hello
OK
Error
What will be the output of the following C code?
3 2 3
2 2 3
3 2 2
2 3 3
What will be the output of the following C code?
Run time error
7
8
Depends on compiler
What will be the output of the following C code?
Hi is printed 9 times
Hi is printed 8 times
Hi is printed 7 times
Hi is printed 6 times
What will be the output of the following C code?
H
H is printed infinite times
Compile time error
Varies
What will print?
10
20
30
40
Find error/ output in following code
int main ()
{
int i = 0;
for ( ; ;)
printf ( "%d", i) ;
return 0;
}
O times
Infinite times
10 times
1 times
which is the only function all C programs must contain?
start()
sys()
main()
scanf()
Which of the following is not a correct variable type?
float
real
int
double
