Fundamentals Of Data Structure MCQ'S SET-4
1] Which is an indirection operator among the following?
a) &
b) *
c) ->d) .
ANSWER: B
2] Which of the following does not initialize ptr to null (assuming variable declaration of a as int a=0;?
a) int *ptr = &a;
b) int *ptr = &a – &a;
c) int *ptr = a – a;
d) All of the mentioned
ANSWER: A
3] What is the output of this C code?
#include
<stdio.h>
int x = 0;
void main()
{
int *ptr =
&x;
printf("%p\n", ptr);
x++;
printf("%p\n ", ptr);
}
ANSWER: A
4] What is the output of this C code?
#include
<stdio.h>
int x = 0;
void main()
{
int *const ptr
= &x;
printf("%p\n", ptr);
ptr++;
printf("%p\n ", ptr);
}
ANSWER: B
5] What is the output of this C code?
#include
<stdio.h>
void main()
{
int x = 0;
int *ptr =
&x;
printf("%p\n", ptr);
ptr++;
printf("%p\n ", ptr);
}
a) 0xbfd605e8 0xbfd605ec
b) 0xbfd605e8 0cbfd60520
c) 0xbfd605e8 0xbfd605e9
d) Run time error
ANSWER: A
6] What is the output of this C code?
#include
<stdio.h>
void main()
{
int x = 0;
int *ptr =
&5;
printf("%p\n", ptr);
}
ANSWER: D
7] What is the output of this C code?
#include
<stdio.h>
void main()
{
int k = 5;
int *p =
&k;
int **m = &p;
**m = 6;
printf("%d\n", k);
}
ANSWER: C
8] What is the output of this C code?
#include
<stdio.h>
void main()
{
int a[3] = {1,
2, 3};
int *p = a;
int *r =
&p;
printf("%d", (**r));
}
b) Compile time error
ANSWER: B
9] What is the output of this C code?
#include
<stdio.h>
void main()
{
int a[3] = {1,
2, 3};
int *p = a;
int **r =
&p;
printf("%p %p", *r, a);
}
b) 1 2
c) Same address is printed.
d) 1 1
ANSWER: C
10] How many number of pointer (*) does C have against a pointer variable declaration?
a) 7b) 127
ANSWER: D
11] What is the output of this C code?
#include
<stdio.h>
int main()
{
int a = 1, b =
2, c = 3;
int *ptr1 =
&a, *ptr2 = &b, *ptr3 = &c;
int **sptr =
&ptr1; //-Ref
*sptr = ptr2;
}
a) ptr1 points to a
b) ptr1 points to b
c) sptr points to ptr2
d) None of the mentioned
ANSWER: B
12] What is the output of this C code?
#include
<stdio.h>
void main()
{
int a[3] = {1,
2, 3};
int *p = a;
int **r =
&p;
printf("%p %p", *r, a);
}
b) 1 2
ANSWER: C
13] What substitution should be made to //-Ref such that ptr1 points to variable C?
#include
<stdio.h>
int main()
{
int a = 1, b =
2, c = 3;
int *ptr1 = &a;
int **sptr =
&ptr1;
//-Ref
}
ANSWER: A
14] Which of the following declaration throw run-time error?
a) int **c = &c;b) int **c = &*c;
ANSWER: D
15] Comment on the output of this C code?
#include
<stdio.h>
int main()
{
int a = 10;
int **c -=
&&a;
}
ANSWER: B
16] What is the output of this C code?
#include
<stdio.h>
void main()
{
int a[3] = {1,
2, 3};
int *p = a;
int *r =
&p;
printf("%d",
(**r));
}
ANSWER: B
17] Comment on the output of this C code?
#include
<stdio.h>
int main()
{
char *str =
"This" //Line 1
char *ptr =
"Program\n"; //Line 2
str = ptr; //Line 3
printf("%s, %s\n", str, ptr); //Line 4
}
a) Memory holding “this” is cleared at line 3
b) Memory holding “this” loses its reference at line 3
c) You cannot assign pointer like in Line 3
d) Output will be This, Program
ANSWER: B
18] What type initialization is needed for the segment “ptr[3] = ’3′;” to work?
a) char *ptr = “Hello!”;ANSWER: B
19] The syntax for constant pointer to address (i.e., fixed pointer address) is:
a) const <type> * <name>
b) <type> * const <name>
c) <type> const * <name>
d) Both (a) and (c)
ANSWER: B
20] Comment on the output of this C code?
#include
<stdio.h>
int add(int a, int
b)
{
return a + b;
}
int main()
{
int
(*fn_ptr)(int, int);
fn_ptr = add;
printf("The sum of two numbers is: %d", (int)fn_ptr(2, 3));
}