Cs3251 Pic QB Unit-3
Cs3251 Pic QB Unit-3
E
Anna University Regulation: 2021
O
C
CS3251- Programming in C
E
I Year/II Semester
AC
Question Bank
R
G
Prepared By,
Ms. S. Abarna, AP/CSE
CS3251_PIC
4931_Grace College of Engineering,Thoothukudi
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.
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
E
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
O
memory
4. What are * and & operators means?
„*‟ operator means „value at the address‟ „&‟ operator means „address of‟
5. What is meant by Preprocessor?
C
Preprocessor is the program, that process our source program before the compilation.
6. How can you return more than one value from a function?
E
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?
AC
allocated space.
It cannot be resized. It can be resized using
G
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
4931_Grace College of Engineering,Thoothukudi
E
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,
O
the compiler-generated code complains with null pointer assignment.
15. Write the syntax for including functions?
The syntax for including functions in program is
C
return_type function_name(datatype var1, datatype var2,…);
//FUNCTION DECLARATION
int main()
E
{
variable_name = function_name(var1, var2, …);
//FUNCTION CALL
AC
…..
Return 0;
}
return_type function_name(datatype var1, datatype var2,…)
R
//FUNCTION DEFINITION
{
…..
G
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
4931_Grace College of Engineering,Thoothukudi
E
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
O
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?
C
An array of pointers is an indexed set of variables in which the variables
are pointers (a reference to a location in memory).
E
Pointers are an important tool for creating, using, and destroying all types of data
structures.
AC
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
4931_Grace College of Engineering,Thoothukudi
E
traced.
Reduces the size of the code, duplicate set of statements are replaced by function
O
calls.
29. What is the output of the following code fragment? (May 19)
int =456, *p1, **p2;
p1=&x;
C
p2=&p1;
printf(“Value of x is: %d\n”, x);
E
printf(“Value of *p1 is: %d\n”, *p1);
printf(“Value of *p2 is: %d\n”, *p2);
AC
Output:
Value of x is: 456
Value of *p1 is: 456
Value of *p2 is: 1640617564
UNIT-III / PART-B
R
CS3251_PIC
4931_Grace College of Engineering,Thoothukudi
12. Write a function using pointers to add matrix and to return the resultant matrix to the
calling function. (May 08)
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)
E
O
C
E
AC
R
G
CS3251_PIC