C MCQ set number 00690

1. What is the output of this C code?

  1.     #include <stdio.h>
  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

Answer: c [Reason:] None.

2. What is the output of this C code?

  1.     #include <stdio.h>
  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

Answer: a [Reason:] None.

3. What is the output of this C code?

  1.     #include <stdio.h>
  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

Answer: b [Reason:] None.

4. What is the output of this C code?

  1.     #include <stdio.h>
  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

Answer: a [Reason:] None.

5. What is the output of this C code?

  1.     #include <stdio.h>
  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

Answer: a [Reason:] None.

6. What is the output of this C code?

  1.     #include <stdio.h>
  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

Answer: c [Reason:] None.

7. What is the output of this C code?

  1.     #include <stdio.h>
  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

Answer: c [Reason:] None.

8. What is the output of this C code?

  1.     #include <stdio.h>
  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

Answer: b [Reason:] None.

ed010d383e1f191bdb025d5985cc03fc?s=120&d=mm&r=g

DistPub Team

Distance Publisher (DistPub.com) provide project writing help from year 2007 and provide writing and editing help to hundreds student every year.