1. 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
-
}
a) *sptr = &c;
b) **sptr = &c;
c) *ptr1 = &c;
d) none of the mentioned.
Answer
Answer: a [Reason:] None.
2. Which of the following declaration throw run-time error?
a) int **c = &c;
b) int **c = &*c;
c) int **c = **c;
d) none of the mentioned
Answer
Answer: d [Reason:] None.
3. Comment on the output of this C code?
-
#include <stdio.h>
-
int main()
-
{
-
int a = 10;
-
int **c -= &&a;
-
}
a) You cannot apply any arithmetic operand to a pointer
b) We don’t have address of an address operator
c) We have address of an address operator
d) None of the mentioned.
Answer
Answer: b [Reason:] None.
4. What is the output of this C code?
-
#include <stdio.h>
-
void main()
-
{
-
int k = 5;
-
int *p = &k;
-
int **m = &p;
-
printf("%d%d%dn", k, *p, **m);
-
}
a) 5 5 5
b) 5 5 junk value
c) 5 junk junk
d) Compile time error
Answer
Answer: a [Reason:] None.
5. What is the output of this C code?
-
#include <stdio.h>
-
void main()
-
{
-
int k = 5;
-
int *p = &k;
-
int **m = &p;
-
printf("%d%d%dn", k, *p, **p);
-
}
a) 5 5 5
b) 5 5 junk value
c) 5 junk junk
d) Compile time error
Answer
Answer: d [Reason:] None.
6. 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("%dn", k);
-
}
a) 5
b) Run time error
c) 6
d) Junk
Answer
Answer: c [Reason:] None.
7. 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));
-
}
a) 1
b) Compile time error
c) Address of a
d) Junk value
Answer
Answer: b [Reason:] None.