250+ TOP MCQs on Address Arithmetic and Answers

C helps anyone preparing for Tech Mahindra and other companies C interviews. One should practice these Objective Questions and answers continuously for 2-3 months to clear Tech Mahindra interviews on C Programming language.

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

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

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

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

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

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

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

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

  1.     #include 
  2.     int main()
  3.     {
  4.         void *p;
  5.         int a[4] = {1, 2, 3, 8};
  6.         p = &a[3];
  7.         int *ptr = &a[2];
  8.         int n = p - ptr;
  9.         printf("%dn", n);
  10.     }

a) 1
b) Compile time error
c) Segmentation fault
d) 4
Answer: b
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         void *p;
  5.         int a[4] = {1, 2, 3, 4};
  6.         p = &a[3];
  7.         int *ptr = &a[2];
  8.         int n = (int*)p - ptr;
  9.         printf("%dn", n);
  10.     }

a) 1
b) Compile time error
c) Segmentation fault
d) 4
Answer: a
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int a[4] = {1, 2, 3, 4};
  5.         int b[4] = {1, 2, 3, 4};
  6.         int n = &b[3] - &a[2];
  7.         printf("%dn", n);
  8.     }

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

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int a[4] = {1, 2, 3, 4};
  5.         int *p = &a[1];
  6.         int *ptr = &a[2];
  7.         ptr = ptr * 1;
  8.         printf("%dn", *ptr);
  9.     }

a) 2
b) 1
c) Compile time error
d) Undefined behaviour
Answer: c
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int a[4] = {1, 2, 3, 4};
  5.         int *ptr  =  &a[2];
  6.         float n = 1;
  7.         ptr = ptr + n;
  8.         printf("%dn", *ptr);
  9.     }

a) 4
b) 3
c) Compile time error
d) Undefined behaviour
Answer: c
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int a[4] = {1, 2, 3, 4};
  5.         void *p = &a[1];
  6.         void *ptr = &a[2];
  7.         int n = 1;
  8.         n = ptr - p;
  9.         printf("%dn", n);
  10.     }

a) 1
b) 4
c) Compile time error
d) Depends on the compiler
Answer: b
Clarification: None.

Leave a Reply

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