0% found this document useful (0 votes)
6 views6 pages

Unit 3 - 2 Marks and 13 Marks

The document is a question bank for the course CS3251 - Programming in C, focusing on Arrays, Functions, and Pointers. It includes definitions, explanations, and examples related to recursive functions, pointers, parameter passing, and built-in functions. Additionally, it provides a series of questions and programming tasks for students to practice their understanding of these concepts.

Uploaded by

TJS CSE HOD
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views6 pages

Unit 3 - 2 Marks and 13 Marks

The document is a question bank for the course CS3251 - Programming in C, focusing on Arrays, Functions, and Pointers. It includes definitions, explanations, and examples related to recursive functions, pointers, parameter passing, and built-in functions. Additionally, it provides a series of questions and programming tasks for students to practice their understanding of these concepts.

Uploaded by

TJS CSE HOD
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

1128 TJSEC

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

TJSEC BE- Computer Science &

Engineering Anna University

Regulation: 2021 CS3251-

Programming in C

I Year/II Semester

Question Bank

Unit – II Arrays and


Unit- III Functions and Pointers

Prepared By,
Ms. PAVITHRA V, AP/CSE

CS3251_PIC
1128 TJSEC

FUNCTIONS AND POINTERS


Modular programming - Function prototype, function definition, function call, Built-in functions
(string functions, math functions) – Recursion, Binary Search using recursive functions – Pointers
– Pointer operators – Pointer arithmetic – Arrays and pointers – Array of pointers – Parameter
passing: Pass by value, Pass by reference.

UNIT-III / PART-A
1. What is meant by Recursive function?
If a function calls itself again and again, then that function is called Recursive function.
2. What is a Pointer? How a variable is declared to the pointer?
Pointer is a variable which holds the address of another variable.

TJSEC
Pointer Declaration: datatype *variable-name;
Example: int *x, c=5; x=&a;
3. What are the uses of Pointers?
Pointers are used to return more than one value to the function, Pointers are more
efficient in handling the data in arrays, Pointers reduce the length and complexity of the
program, They increase the execution speed, The pointers saves data storage space in
memory
4. What are * and & operators means?
„*‟ operator means „value at the address‟ „&‟ operator means „address of‟
5. What is meant by Preprocessor?
Preprocessor is the program, that process our source program before the compilation.
6. How can you return more than one value from a function?
A Function returns only one value. By using pointer we can return more than one value.
7. Is it possible to place a return statement anywhere in „C‟ program?
Yes. The return statement can occur anywhere.
8. What is the difference between an array and pointer?
Array Pointer

Array allocates space automatically. Pointer is explicitly assigned to point to an


allocated space.
It cannot be resized. It can be resized using
realloc (),
It cannot be reassigned, Size of(array Pointers can be reassigned, Sezeof(pointer
name) gives the number of bytes occupied name) returns the number of bytes used to
by the array. store the pointer variable.
9. What is dangling pointer?
In C, a pointer may be used to hold the address of dynamically allocated. Memory After
this memory is freed with the free() function, the pointer itself will still contain the
address of the released block. This is referred to as a dangling pointer. Using the
pointer
in this state is a serious programming error. Pointer should be assigned NULL after
freeing memory to avoid this bug.
10. Is using exit() the same as using return?
No. The exit() function is used to exit your program and return control to the operating
system. The return statement is used to return from a function and return control to the
calling function. If you issue a return from the main() function, you are essentially
returning control to the calling function, which is the operating system. In this case, the
return statement and exit() function are similar.

CS3251_PIC
1128 TJSEC

11. What is stack trace?


A "stack trace" is a list of which functions have been called, based on this information.
When you start using a debugger, one of the first things you should learn is how to get a
stack trace. The stack is very inflexible about allocating memory; everything must be
deallocated in exactly the reverse order it was allocated in.
12. What is meant by Recursive function?
If a function calls itself again and again, then that function is called Recursive function.
13. What is the difference between NULL and NUL?
NUL is the name of the first character in the ASCII character set. It corresponds to a zero
value. There's no standard macro NUL in C, but some people like to define it. NULL can
be defined as ((void*)0), NUL as '\0'. Both can also be defined simply as 0. If they're
defined that way, they can be used interchangeably.
14. What is a "null pointer assignment" error? What are bus errors, memory faults, and
core dumps?

TJSEC
Null pointer assignment is a message you might get when an MS-DOS program finishes
executing. Some such programs can arrange for a small amount of memory to be
available "where the NULL pointer points to" (so to speak). If the program tries to write
to that area, it will overwrite the data put there by the compiler. When the program is
done, code generated by the compiler examines that area. If that data has been changed,
the compiler-generated code complains with null pointer assignment.
15. Write the syntax for including functions?
The syntax for including functions in program is
return_type function_name(datatype var1, datatype var2,…);
//FUNCTION DECLARATION
int main()
{
variable_name = function_name(var1, var2, …);
//FUNCTION CALL
…..
Return 0;
}
return_type function_name(datatype var1, datatype var2,…)
//FUNCTION DEFINITION
{
…..
statements
……
return(variable);
}
16. What is Pointer Arithmetic?
A pointer is an address, which is a numeric value. Therefore, you can perform
arithmetic operations on a pointer just as you can on a numeric value. There are four
arithmetic operators that can be used on pointers: ++, --, +, and -.
17. How does free() know how much memory to release?
There's no standard way. It can vary from compiler to compiler, even from version to
version of the same compiler. free(), malloc(), calloc(), and realloc() are functions; as long
as they all work the same way, they can work any way that works.

CS3251_PIC
1128 TJSEC

18. Can math operations be performed on a void pointer?


No. Pointer addition and subtraction are based on advancing the pointer by a number
of elements. By definition, if you have a void pointer, you don't know what it's pointing
to, so you don't know the size of what it's pointing to. If you want pointer arithmetic
to
work on raw addresses, use character pointers.
19. What is a void pointer?
A void pointer is a C convention for "a raw address." The compiler has no idea what
type of object a void pointer "really points to." If you write
int *ip;
ip points to an int. If you write void *p; p doesn't point to a void!
20. What is indirection?
If p is a pointer, the value of p is the address of the object. *p means "apply the
indirection operator to p"; its value is the value of the object that p points to. *p is an

TJSEC
lvalue; like a variable, it can go on the left side of an assignment operator, to change the
value. If p is a pointer to a constant, *p is not a modifiable lvalue; it can't go on the left
side of an assignment.
21. What is the difference between far and near pointers?
Compilers for PC compatibles use two types of pointers.
 near pointers are 16 bits long and can address a 64KB range. far pointers are 32 bits
long and can address a 1MB range.
 near pointers operate within a 64KB segment. There's one segment for function
addresses and one segment for data.
22. What do you mean by array of pointers?
 An array of pointers is an indexed set of variables in which the variables
are pointers (a reference to a location in memory).
 Pointers are an important tool for creating, using, and destroying all types of data
structures.
Example: int *ptr[10];
The above statement declares array of an array of 10 pointers where each of the pointer
points to an integer variable.
23. What is built-in functions?
The standard library functions are built-in functions to handle tasks such as
mathematical computations, I/O processing, string handling etc. Built-in function is a
set of code that takes a finite number of input and optionally returns a
value. These functions are defined in the header file. Functions that operate on string
expression are classified as string functions, they include functions for finding the length
of a given text, remove certain words from a text etc.
24. Why should I prototype a function?
A function prototype tells the compiler what kind of arguments a function is looking to
receive and what kind of return value a function is going to give back. This approach
helps the compiler ensure that calls to a function are made correctly and that no
erroneous type conversions are taking place.
25. Should a function contain a return statement if it does not return a value?
In C, void functions (those that do not return a value to the calling function) are not
required to include a return statement. Therefore, it is not necessary to include a
return statement in your functions declared as being void. In some cases, your function
might trigger some critical error, and an immediate exit from the function might be
necessary.
In this case, it is perfectly acceptable to use a return statement to bypass the rest of the
function's code.

CS3251_PIC
1128 TJSEC

26. How do you use a pointer to a function?


The hardest part about using a pointer-to-function is declaring it. Consider an example.
You want to create a pointer, pf, that points to the strcmp() function. The strcmp()
function is declared in this way:
int strcmp( const char *, const char * )
27. List the advantage of recursion. (May 18)
 Reduce unnecessary calling of function.
 Through Recursion one can Solve problems in easy way while its iterative solution
is very big and complex.For example to reduce the code size for Tower of Honai
application, a recursive function is bet suited.
 Extremely useful when applying the same solution.
28. What is the need for functions? (May 19)
Functions are used because of following reasons
 To improve the readability of code.

TJSEC
 Improves the reusability of the code, same function can be used in any program
rather than writing the same code from scratch.
 Debugging of the code would be easier if you use functions, as errors are easy to be
traced.
 Reduces the size of the code, duplicate set of statements are replaced by function
calls.
29. What is the output of the following code fragment? (May 19)
int =456, *p1, **p2;
p1=&x;
p2=&p1;
printf(“Value of x is: %d\n”, x);
printf(“Value of *p1 is: %d\n”, *p1);
printf(“Value of *p2 is: %d\n”, *p2);
Output:
Value of x is: 456
Value of *p1 is: 456
Value of *p2 is: 1640617564
UNIT-III / PART-B
1. When is a null pointer used? (May 18)
2. What do you mean by Call by reference? Explain with an example.
3. What do you mean by Call by Value? Explain with an example.
4. Write a „C‟ Program to interchange two values using call by reference (or)
What is pass by reference? Explain swapping of 2 values using pass by reference in „C‟.
(May 19)
5. Can you subtract pointers from each other? Why would you?
6. How do you use a pointer to a function? When would you use a pointer to a function?
7. Write a C program to generate Fibonacci series using function.
8. Write a C Program to find factorial of a given number using recursive function.
9. What is Pointer? How to pass pointer as an argument in function?
10. How can you pass an array to a function by value?
11. Explain the use of pointers in array handling with an example. (Nov 07)
12. Write a function using pointers to add matrix and to return the resultant matrix to the
calling function. (May 08)

CS3251_PIC
1128 TJSEC

13. (i) Explain the purpose of a function prototype. And specify the difference between the
user defined function and built-in function (May 18)
(ii) Write the C program to find the value of sin(x) using the series up to the given
accuracy (without using user defined function) also print sin(x) using library function.
(May 18)
14. (i) What is difference between pass by value and pass by reference? Write the C coding
for swapping two numbers using pass by reference. (May 18)
(ii) What is recursion? Explain the procedure to compute sin(x) using recursive
functions. Write a C code for the same. (May 19)
15. When is a null pointer used? (May 18)

TJSEC

CS3251_PIC

You might also like