Question Bank C Programming
Question Bank C Programming
1 Pointers
A. Short answer questions
1. Define pointer
2. Write an example of pointer declaration and initialization.
3. What is meant by pointer dereferencing?
4. What is output of following program?
#include<stdio.h>
int main()
{
int a[] = { 1, 2, 3, 4, 5} ;
int *ptr;
ptr = a;
printf(" %d ", *( ptr + 1) );
return 0;
}
5. If a pointer variable stores address of a character variable, then what is the size of pointer?
6. Fill answers in the table based on code below-
NOTE: Address of num is 1002
int num=50, x;
int *ptr;
ptr = #
x=*ptr;
Variable Value
num
&num
Ptr
*ptr
7. Consider size of int=2 bytes, float=4 bytes, char= 1 byte, double=8 bytes. Fill missing values in
below table-
Data type ptr ptr++
int 1000
char 1000
float 1000
double 1000
8. List the various pointer operations.
9. What is the purpose of indirection operator?
10. What is the relationship between array name and pointer?
11. Are the expressions ptr++ and ++ptr same?
12. Write down equivalent pointer expression which does the same job as a[i]
13. List functions used in dynamic memory allocation.
14. Define dynamic memory allocation.
15. List types of pointers in C.
16. What is memory leak?
17. Define dangling pointer.
B. Long answer questions
1. What is pointer? How it is initialized explain with example.
2. Explain the concept of pointer to an array with the help of an example.
3. Explain operations on pointers with an example.
4. Write a program to Swap values of two numbers using pointers
5. Write a program to find the maximum number between two numbers using a pointer
6. Explain the concept of pointer to an array with example.
7. Explain the concept of array of pointers with example.
8. Explain difference between call by value and call by reference.
9. Explain difference between malloc() and calloc()
10. How pointers are passed as arguments to a function? Explain with example.
11. Explain function returning pointer with the help of an example.
Ch. 2 String
1. Short answer questions
1.What is string?
2. What is out put of the following C code?
void main()
{
Char *s=”hello”;
Char * p=s;
printf(“%c\t %c”, *(p+3), s[1]);
}
3.Which standard input-output library functions are used for string input and output respectively?
4. C supports string built in datatype?TRUE/FALSE.
5.What data structure is used to store a string.
Ch5. Preprocessors
A. Short answer questions
1. What is pre processor?
2. What are preprocessor directives?
3. What is macro?
4. Give format of preprocessor directive?
5. Which directives are used for defining a macro?
6. What is the use of file inclusion directive?
7. Define nested macro?