Unit 3 - 2 Marks and 13 Marks
Unit 3 - 2 Marks and 13 Marks
Programming in C
I Year/II Semester
Question Bank
Prepared By,
Ms. PAVITHRA V, AP/CSE
CS3251_PIC
1128 TJSEC
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
CS3251_PIC
1128 TJSEC
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
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
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