C MCQ set number 00699

1. What is the output of this C code?

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

a) Compile time error
b) Undefined behaviour
c) hello
d) None of the mentioned

Answer

Answer: c [Reason:] None.

2. What is the output of this C code?

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

a) Compile time error
b) Undefined behaviour
c) hello
d) Address of hello

Answer

Answer: b [Reason:] None.

3. What is the output of this C code?

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

a) Compile time error
b) Undefined behaviour
c) 0
d) Some garbage value

Answer

Answer: c [Reason:] None.

4. What is the output of this C code?

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

a) Compile time error
b) Undefined behaviour
c) 0
d) Some garbage value

Answer

Answer: c [Reason:] None.

5. What is the output of this C code?

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

a) Compile time error
b) Undefined behaviour
c) 1
d) Some garbage value

Answer

Answer: d [Reason:] None.

6. Which of the following are generated from char pointer?
a) char *string = “Hello.”;
b) char *string;
    scanf(“%s”, string);
c) char string[] = “Hello.”;
d) char *string = “Hello.”; and char string[] = “Hello.”;

Answer

Answer: a [Reason:] None.

7. Which of the following declaration are illegal?
a) int a[][] = {{1, 2, 3}, {2, 3, 4, 5}};
b) int *a[] = {{1, 2, 3}, {2, 3, 4, 5}};
c) int a[4][4] = {{1, 2, 3}, {2, 3, 4, 5}};
d) none of the mentioned

Answer

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