C Programming Questions and Answers on Initialization of Pointer Arrays for Freshers

1. To declare a 3 dimension array using pointers, which of the following is the correct syntax:

a) char *a[][];
b) char **a[];
c) char ***a;
d) all of the mentioned
Answer: a
2. Comment on the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         char *a = {"p", "r", "o", "g", "r", "a", "m"};
  5.         printf("%s", a);
  6.     }
a) Output will be program
b) Output will be p
c) No output
d) Compile-time error
Answer: b
3. An array of strings can be initialized by:

a) char *a[] = {“Hello”, “World”};
b) char *a[] = {“Hello”, “Worlds”};
c) char *b = “Hello”;
    char *c = “World”;
    char *a[] = {b, c};
d) All of the mentioned
Answer: d
4. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         char *a[10] = {"hi", "hello", "how"};
  5.         int i = 0;
  6.         for (i = 0;i < 10; i++)
  7.         printf("%s", *(a[i]));
  8.     }
a) segmentation fault
b) hi hello how followed by 7 null values
c) 10 null values
d) depends on compiler
Answer: a
5. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         char *a[10] = {"hi", "hello", "how"};
  5.         int i = 0, j = 0;
  6.         a[0] = "hey";
  7.         for (i = 0;i < 10; i++)
  8.         printf("%s\n", a[i]);
  9.     }
a) hi hello how Segmentation fault
b) hi hello how followed by 7 null values
c) hey hello how Segmentation fault
d) depends on compiler
Answer: c
6. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         char *a[10] = {"hi", "hello", "how"};
  5.         printf("%d\n", sizeof(a));
  6.     }
a) 10
b) 13
c) Run time error
d) 40
Answer: d
7. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         char *a[10] = {"hi", "hello", "how"};
  5.         printf("%d\n", sizeof(a[1]));
  6.     }
a) 6
b) 4
c) 5
d) 3
Answer: b
8. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         char *a[10] = {"hi", "hello", "how"};
  5.         int i = 0;
  6.         for (i = 0;i < 10; i++)
  7.         printf("%s", a[i]);
  8.     }
a) hi hello how Segmentation fault
b) hi hello how null
c) hey hello how Segmentation fault
d) hi hello how followed by 7 nulls
Answer: d
9. What is the output of this C code?
  1.     #include 
  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: c
10. What is the output of this C code?
  1.     #include 
  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: b
11. What is the output of this C code?
  1.     #include 
  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: c
12. What is the output of this C code?
  1.     #include 
  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: c
13. What is the output of this C code?
  1.     #include 
  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: d
14. 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: a
15. 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: a

Related

C# Questions & Answers on IF Statements for Freshers

1. Select the output for the following set of code : static void Main(string[] args) { int i = 30; int j = 25 % 25; if (Convert.ToBoolean(Convert.ToInt32(i = j))) ...

C# Questions & Answers on Bitwise and Conditional Operators for Freshers

1. Select the relevant output for the following set of code : static void Main(string[] args) { byte varA = 10; byte varB = 20; long result = varA & varB; Cons...

C# Questions & Answers on Relational and Logical Operators for Freshers

1. Select the relevant output for the following set of code: static void Main(string[] args) { int a = 4; int b = 5; int c = 6; int d = 8; if (((a * b / c) +...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item