C Programming and Data Structures - CS3353 - Important Questions With Answer - Unit 2 - C Programming Advanced Features
C Programming and Data Structures - CS3353 - Important Questions With Answer - Unit 2 - C Programming Advanced Features
Question Bank
Unit- II C PROGRAMMING-ADVANCED
FEATURES
CS3353_CPDS
https://play.google.com/store/apps/details?
CS3353- C Programming and Data
Structures
UNIT-II / PART-A
1. 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;
2. 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
3. What are * and & operators means?
„*‟ operator means „value at the address‟ „&‟ operator means „address of‟
4. What is meant by Preprocessor?
Preprocessor is the program, that process our source program before the compilation.
5. 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.
6. Is it possible to place a return statement anywhere in „C‟ program?
Yes. The return statement can occur anywhere.
7. What is the difference between an array and pointer?
Array Pointer
CS3353_CPDS
https://play.google.com/store/apps/details?
CS3353- C Programming and Data
Structures
11. 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.
12. What is a "null pointer assignment" error? What are bus errors, memory faults, and
core dumps?
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.
13. 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);
}
14. 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 -.
15. 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.
16. 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.
17. 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!
9
CS3353_CPDS
https://play.google.com/store/apps/details?
CS3353- C Programming and Data Structures
18. 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 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.
19. 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.
20. What do you mean by array of pointers?
An array of pointers is an indexed set of variables in which the variablesare
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.
21. 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 * )
22. 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.
23. What is the need for functions? (May 19)
Functions are used because of following reasons
To improve the readability of code.
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.
CS3353_CPDS
https://play.google.com/store/apps/details?
CS3353- C Programming and Data Structures
26. Give the rules for defining preprocessor.
# pound symbol used before preprocessor directive
# must be first character in source file or first non white space character in a line
New line character ends preprocessor directive
Only single space/tab space allowed between preprocessing tokens
Can appear anywhere in program but generally paced in beginning of
program The preprocessor cannot have termination with semicolon.
27. 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
28. What is the use of pre-processor directives? (May 14,15, 19)
It makes programs easier to develop,
easier to read,
easier to modify
C code more transportable between different machine architectures.
29. What is the use of #define processor? (Dec 14)
#define directive is used to define Macros –which are tokens that can be replaced foruser
defined sequence of characters
Syntax: #define macro-name replacement-list
Example: #define PI 3.14
11
CS3353- C Programming and Data Structures
CS3353_CPDS
https://play.google.com/store/apps/details?
UNIT-II / 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)
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 givenaccuracy
(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 codingfor
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)
12
CS3353_CPDS
https://play.google.com/store/apps/details?