C MCQ set number 00694

1. What is the output of this C code (considering sizeof char is 1 and pointer is 4)?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         char *a[2] = {"hello", "hi"};
  5.         printf("%d", sizeof(a));
  6.         return 0;
  7.     }

a) 9
b) 4
c) 8
d) 10

Answer

Answer: c [Reason:] None.

2. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         char a[2][6] = {"hello", "hi"};
  5.         printf("%d", sizeof(a));
  6.         return 0;
  7.     }

a) 9
b) 12
c) 8
d) 10

Answer

Answer: b [Reason:] None.

3. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         char a[2][6] = {"hello", "hi"};
  5.         printf("%s", *a + 1);
  6.         return 0;
  7.     }

a) hello
b) hi
c) ello
d) ello hi

Answer

Answer: c [Reason:] None.

4. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         char *a[2] = {"hello", "hi"};
  5.         printf("%s", *(a + 1));
  6.         return 0;
  7.     }

a) hello
b) ello
c) hi
d) ello hi

Answer

Answer: c [Reason:] None.

5. Advantage of a multi-dimension array over pointer array.
a) Pre-defined size.
b) Input can be taken from user.
c) Faster Access.
d) All of the mentioned

Answer

Answer: d [Reason:] None.

6. Which of the following operation is possible using a pointer char?
    (Assuming declaration char *a;)
a) Input via %s
b) Generation of multidimensional array
c) Changing address to point at another location
d) All of the mentioned

Answer

Answer: c [Reason:] None.

7. Comment on the following two operations?
    int *a[] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 1
    int b[4][4] = {{1, 2, 3}, {1, 2, 3, 4}};//- 2
a) 1 will work, 2 will not
b) 1 and 2, both will work
c) 1 won’t work, 2 will work
d) Neither of them will work

Answer

Answer: c [Reason:] None.

8. Comment on the following two operations?
    int *a[] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 1
    int b[][] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 2
a) 1 works, 2 doesn’t
b) 2 works, 1 doesn’t
c) Both of them work
d) Neither of them work

Answer

Answer: d [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.