Unit 4 MCQ
Unit 4 MCQ
Unit 4 MCQ
1. How will you declare the function which is intended to receive an array as an argument
a. return_type function(type arrayname[])
b. return_type function(type arrayname[SIZE])
c. return_type function(type *arrayname)
d. All of the above
Ans: d
2. To store the array returned from the function, we can define a ______ which points to
that array.
a. Structure
b. Array
c. Pointer
d. List
Ans: c
Ans: a
Ans: a
Ans: a
7. The ________ preprocessor directive is used to paste code of given file into current file.
a. #define
b. #include
c. #ifdef
d. #pragma
Ans: b
Ans: c
Ans: d
Ans: a
Ans: d
Ans: b
13. Identify the value that gets printed in the following program
#include <stdio.h>
int main()
{
int a=10; //variable declaration
int *p; //pointer variable declaration
p=&a; //store address of variable a in pointer p
printf("Address stored in a variable p is:%x\n",p); //accessing the address
printf("Value stored in a variable p is:%d\n",**p); //accessing the value
return 0;
}
a. 10 10
b. 10, 60ff08
c. 60ffd, 10
d. None of the above
Ans: a
Ans: c
15. A pointer to void means a ________ pointer that can point to any data type.
a. Specific
b. Generic
c. Exact
d. Null
Ans: b
16. Select the possible arithmetic operations are applicable on the pointer in C language:
a. Increment, Decrement
b. Addition, Subtraction
c. Comparison
d. All of the above
Ans: d
#include<stdio.h>
void main ()
{
int arr[5] = {1, 2, 3, 4, 5};
int *p = arr;
int i;
printf("printing array elements...\n");
for(i = 0; i< 5; i++)
{
printf("%d ",*(p+i));
}
}
a. 1, 2, 3, 4, 5
b. 5, 4, 3, 2, 1
c. 1, 2, 3, 5, 8
d. None of the above
Ans: a
Ans: d
#include<stdio.h>
int addition ();
int main ()
{
int result;
int (*ptr)();
ptr = &addition;
result = (*ptr)();
printf("The sum is %d",result);
}
int addition()
{
int a=5, b=2;
return a+b;
}
a. 10
b. 3
c. 7
d. 25
Ans: c
20. A ______ pointer in C cannot change the address of the variable to which it is pointing
a. Fixed
b. Null
c. Void
d. Constant
Ans: d
21. An array of pointers to strings is an array of character pointers where each pointer points
to the ________ of the string or the __________ of the string.
a. first character, base address
b. last character, last address
c. middle character, middle address
d. None of the above
Ans: a
22. A function pointer points to _____, not ____.
a. data, code
b. code, data
c. type, const
d. None of the above
Ans: b
23. Identify the correct function pointer declaration:
a. int * foo(int)
b.int (*foo)(int);
c. int (int)(*foo)
d. None of the above
Ans: b
24. What is the output of the given program:
#include <stdio.h>
void Hi_function (int times); /* function */
int main() {
void (*function_ptr)(int); /* function pointer Declaration */
function_ptr = Hi_function; /* pointer assignment */
function_ptr (3); /* function call */
return 0;}
void Hi_function (int times) {
int k;
for (k = 0; k < times; k++) printf("Hi");}
a. Hi Hi Hi Hi Hi Hi
b.Hi Hi Hi Hi Hi
c. Hi Hi Hi Hi
d.Hi Hi Hi
Ans. d
25. What is the output of the given program:
#include <stdio.h>
void* cube (const void* num);
int main() {
int x, cube_int;
x = 4;
cube_int = cube (&x);
printf("%d cubed is %d\n", x, cube_int);
return 0;}
Ans. d