250+ TOP MCQs on Address Arithmetic and Answers

C questions and puzzles on “Address Arithmetic”. One shall practice these questions and puzzles to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These programming puzzles can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C questions and puzzles on “Address Arithmetic” along with answers, explanations and/or solutions:

1. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         double *ptr = (double *)100;
  5.         ptr = ptr + 2;
  6.         printf("%u", ptr);
  7.     }

a) 102
b) 104
c) 108
d) 116
Answer: d
Clarification:None

2. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int *p = (int *)2;
  5.         int *q = (int *)3;
  6.         printf("%d", p + q);
  7.     }

a) 2
b) 3
c) 5
d) Compile time error
Answer: d
Clarification: None.

3. Which of the following arithmetic operation can be applied to pointers a and b?
(Assuming initialization as int *a = (int *)2; int *b = (int *)3;)
a) a + b
b) a – b
c) a * b
d) a / b
Answer: b
Clarification: None.

4. What is the size of *ptr in a 32-bit machine (Assuming initialization as int *ptr = 10;)?
a) 1
b) 2
c) 4
d) 8
Answer: c
Clarification: None.

5. Which of following logical operation can be applied to pointers?
(Assuming initialization int *a = 2; int *b = 3;)
a) a | b
b) a ^ b
c) a & b
d) None of the mentioned
Answer: d
Clarification: None.

6. What will be the output of the following C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         char *s = "hello";
  5.         char *p = s;
  6.         printf("%ct%c", *(p + 1), s[1]);
  7.     }

a) h e
b) e l
c) h h
d) e e
Answer: d
Clarification: None.

7. What will be the output of the following C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         char *s = "hello";
  5.         char *p = s;
  6.         printf("%ct%c", *p, s[1]);
  7.     }

a) e h
b) Compile time error
c) h h
d) h e
Answer: d
Clarification: None.

8. What will be the output of the following C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         char *s = "hello";
  5.         char *n = "cjn";
  6.         char *p = s + n;
  7.         printf("%ct%c", *p, s[1]);
  8.     }

a) h e
b) Compile time error
c) c o
d) h n
Answer: b
Clarification: None.

Leave a Reply

Your email address will not be published. Required fields are marked *