2 Marks Definition Answers, Multiple Choice Questions - Computer Programming C: Functions and Pointers
2 Marks Definition
Answers
•
A function is a set of instructions
that are used to perform specified tasks which repeatedly occurs in the main
program.
•
Function is used to provide modularity to the software. By using function we
can divide complex tasks into manageable tasks. The function can also help to
avoid duplication of work.
•
The function defined by the users according to their requirements is called user‒defined functions. The users can
modify the function according to their requirement.
•
Actual parameters are transferred
from the calling program (main program) to the called program (function).
•
Formal parameters are transferred
into the calling function (main program) from the called program (function).
•
The return statement may or may not
send back any values to the main program (calling program). If it does, it can
be done using the return statement.
•
Automatic variables: The variables
without any storage class specification are considered as automatic variables.
They are called as automatic because their memory space is automatically
allocated as the variable is declared.
•
The static variable may be an
internal or external type, depending upon where it is declared. If declared
outside the function body, it will be static or global. In case it will be
declared in the body or block it will be auto variable.
•
The external variables are declared
out of the main() function.
availability of these variables are through out the program and that is both in
main program and inside the user defined functions.
•
Registers are special storage areas
within a computer's Central Processing Unit. The actual arithmetic and logical
operation that comprise a program are carried out with in these registers.
•
Function prototypes.
i)
Function with no arguments and no return value.
ii)
Function with arguments and no return value.
iii)
Function with arguments and with return value.
iv)
Function with no arguments and with return value.
•
Call by value: This method copies
the values of actual parameters into the formal parameters of the function.
Here, the changes of the formal parameters cannot affect the actual parameters,
because formal arguments are photocopy of actual arguments.
•
Call by Reference is another way of
passing parameters to the function. Here, the address of arguments are copied
into the parameters inside the function, the address is used to access the
actual arguments used in the call. Hence changes made in the arguments are
permanent.
•
Recursion is a programming technique
that allows the programmer to express operations in terms of themselves. In C,
this takes the form of a function that calls itself.
•
The Tower of Hanoi is a children's playing game, played with three poles and a
number of different sized disks, each disk has a hole in center, allowing it to
be stacked around any of the poles.
•
sqrt(x): This function evaluates
square root 'x'. Note that the argument must be non‒negative.
•
log(x): Where the argument 'x' must
be real. Here loge x is evaluated.
• abs(x):
The abs() function evaluates the absolute value of an integer quantity.
• exp(x):
This function evaluates ex. Its general form is exp(). The argument
x must be a real quantity. 'e' is a mathematical constant between 2 and 3.
• ceil(x):
This evaluates the ceiling of the value x. Ceiling of a number 'x' is the
smallest integer greater than or equal to 'x'.
• fmod(x,y):
Where the arguments may be integer or float values. This functions returns the
remainder, when ‘x' is divided by ‘y’.
•
A pointer is a variable, it may
contain the memory address of another variable. Pointer can have any name that
is legal for other variable. It is declared in the same manner like other
variables. It is always denoted by '*' operator.
•
A pointer is a variable whose value is also an address. Each variable has two
attributes: address and value. A variable can take any value
specified by its data type. A pointer to an integer is a variable that can
store the address of that integer.
•
Null Pointer: A pointer is said to
be a null pointer when its right value is 0. A null pointer can never point to
a valid data. For checking a pointer, if it is assigned to 0, then it is a null
pointer and is not valid.
•
Pointer Expressions: Pointer
variables can be used in expressions. Here, the pointers are preceded by the
*(indirection operator) symbol.
•
Dynamic memory allocation means, a
program can obtain its memory while it is running. It allows us to allocate
additional memory space or to release unwanted space at the time of program
execution (runtime).
•
Pointers support the dynamic memory allocation in 'C' language. The 'C'
language provides four library functions known as 'Memory Management Functions' which can be used for allocating and
releasing memory during execution.
•
The malloc() function is used to
allocate block of memory (i.e.) it allocates a block of memory of specified
size and return a pointer of type void.
•
The free() function is used to
release the previously allocated memory space using malloc() or calloc()
i.e., it is the opposite of malloc()
function.
•
The calloc() function is used for
allocating memory space during the program execution for derived data types
such as arrays, structures, etc.
•
The malloc() allocates a single
block of memory where as calloc()
allocates multiple block of memory with same size and initializes them with
zeros.
MULTIPLE CHOICE
QUESTIONS
1. The keyword used to transfer
control from a function back to the calling function is
A.
switch
B.
goto
C.
go back
D.
return
2. How many times the program will
print "VRB" ?
#include
<stdio.h>
int
main()
{
printf("VRB");
main();
return
0;
}
A.
Infinite times
B.
32767 times
C.
65535 times
D.
Till stack overflows
3. What is (void*)0?
A.
Representation of NULL pointer
B.
Representation of void pointer
C.
Error
D.
None of above
4. Can you combine the following
two statements into one?
char *p;
p =
(char*)malloc(100);
A.
char p = *malloc(100);
B.
char *p = (char) malloc(100);
C.
char *p = (char*)malloc(100);
D.char
*p = (char *)(malloc*)(100);
5. In which header file is the NULL
macro defined?
A.
stdio.h
B.
stddef.h
C.
stdio.h and stddef.h
D.
math.h
6. How many bytes are occupied by near,
far and huge pointers?
A.
near=2 far=4 huge=4
B.
near=4 far=8 huge=8
C.
near=2 far=4 huge=8
D.
near=4 far=4 huge=8
7. If a variable is a pointer to a
structure, then which of the following operator is used to access data members
of the structure through the pointer variable?
A.
.
B.
&
C.
*
D.
‒>
8. What would be the equivalent
pointer expression for referring the array element a[i][j][k][l]
A.
((((a+i)+j)+k)+1)
B.
*(*(*(*(a+i)+j)+k)+1)
C.
(((a+i)+j)+k+1)
D.
((a+i)+j+k+1)
9. A pointer is ther
A.
A keyword used to create variables
B.
A variable that stores address of an instruction
C.
A variable that stores address of other variable
D.
All of the above
10. The operator used to get value
at address stored in a pointer variable is
A.
*
B.
&
C.
&&
D.
||
11. A pointer variable can be
A.
passed to a function as argument.
B.
changed within function.
C.
returned by a function.
D.
assigned an integer value.
12. A self contained block of
statements that perform a coherent task of some kind is called a
A.
Monitor
B.
Function
C.
Program
D.
Structure
13. Recursion is sometimes called
A.
Circular definition
B.
Complex definition
C.
Procedure
D.
Union
14. The name of all functions end
with a
A.
pair of parenthesis
B.
semicolon
C.
braces
D.
colon
15. To access a structure element
using a pointer, _____ operator is used
A.
dot (.)
B.
pointer (&)
C.
pointer (*)
D.
arrow (‒>)
16. The library function sqrt()
operates on a double precision argument. If, i is an integer variable, which
one of the following calls would correctly compute sqrt(i)?
A.
sqrt((double)i)
B.
(double) sqrt(i)
C.
(double) (sqrt(i))
D.
sqrt(i)
17. It is necessary to declare the
type of function in the calling program if
A.
Function returns an integer
B.
Function returns a non‒integer value.
C.
Function is not defined in the same file.
D.
Function is called number of times.
18. The function fprintf is used in
a program
A.
When too many printf calls have been already used in the program.
B.
In place of printf, since printf uses more memory.
C.
When the output is to be printed on to a file.
D.
When the type of variables to be printed are not known be
19. Comment on the following
pointer declaration?
int *ptr, p;
A.
ptr is a pointer to integer, p is not
B.
ptr and p, both are pointers to integer
C.
ptr is a pointer to integer, p may or may not be
D.
ptr and p both are not pointers to integer a
TRUE / FALSE
1.
A function cannot be defined inside another function
True/False
2.
Functions cannot return more than one value at a time
True/False
3.
Functions can be called either by value or reference
True/False
4.
If return type for a function is not specified, it defaults to int
True/False
5.
In C all functions except main() can be called recursively.
True/False
6.
A function may have any number of return statements each returning different values.
True/False
7.
Names of functions in two different files linked together must be unique
True/False
8.
Functions cannot return a floating point number
True/False
9.
Every function must return a value
True/False
10.
If a function contains two return statements successively, the compiler will generate
warnings.
True/False
?
11.
Maximum number of arguments that a function can take is 12
True/False
12.
Usually recursion works slower than loops.
True/False
13.
Is it true that too many recursive calls may result into stack overflow?
True/False
14.
In a function two return statements should never occur.
True/False
15.
Are the expression *ptr++ and ++*ptr are same?
True/False
16.
Are the three declarations char **apple, char *apple[], and char apple[][]
same?
True/False
17.
Is there any difference between the following two statements?
char
*p=0;
char
*t=NULL;
True/False
18.
Is this a correct way for NULL pointer assignment?
int
i=0;
char
*q=(char*)i;
True/False
19.
Is the NULL pointer same as an uninitialised pointer?
True/False
Computer Programming C: UNIT III: Functions and Pointers : Tag: : Computer Programming C - Functions and Pointers of C Programming: 2 Marks Definition Answers
Computer Programming C
CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
English Essentials I
EN25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
தமிழர் மரபு - Heritage of Tamils
UC25H01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Calculus
MA25C01 Maths 1 M1 - 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Physics I
PH25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Chemistry I
CY25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Makerspace
ME25C04 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Computer Programming C
CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Computer Programming Python
CS25C02 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Fundamentals of Electrical and Electronics Engineering
EE25C03 1st Semester EEE Depart | 2025 Regulation | 1st Semester 2025 Regulation
Introduction to Mechanical Engineering
ME25C03 1st Semester Mechanical Dept | 2025 Regulation | 1st Semester 2025 Regulation
Introduction to Civil Engineering
CE25C01 1st Semester Civil, Agri Departments | 2025 Regulation | 1st Semester 2025 Regulation
Essentials of Computing
CS25C03 1st Semester - AIDS, CSE, CSE(CY), IT Department | 2025 Regulation | 1st Semester 2025 Regulation
Applied Physics I Laboratory
PH25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Applied Chemistry I Laboratory
CY25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Computer Programming C Laboratory
CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Computer Programming Python Laboratory
CS25C02 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Engineering Drawing
ME25C01 EEE, Mech, Agri, EEE Depts | 2025 Regulation | 2nd Semester 2025 Regulation
Basic Electronics and Electrical Engineering
EE25C04 1st Semester ECE Dept | 2025 Regulation | 1st Semester 2025 Regulation
Essentials of Computing - Laboratory
CS25C03 1st Semester AIDS, CSE, CSE(CY), IT Depts | practical Laboratory Manual | 2025 Regulation | 1st Semester 2025 Regulation