C Programming Questions and Answers on Character Pointers and Functions for Freshers

1. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         char *str = "hello, world\n";
  5.         char *strc = "good morning\n";
  6.         strcpy(strc, str);
  7.         printf("%s\n", strc);
  8.         return 0;
  9.     }
a) hello, world
b) Crash/segmentation fault
c) Undefined behaviour
d) Run time error
Answer: b
2. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         char *str = "hello world";
  5.         char strc[] = "good morning india\n";
  6.         strcpy(strc, str);
  7.         printf("%s\n", strc);
  8.         return 0;
  9.     }
a) hello world
b) hello worldg india
c) Compile time error
d) Undefined behaviour
Answer: a
3. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         char *str = "hello, world!!\n";
  5.         char strc[] = "good morning\n";
  6.         strcpy(strc, str);
  7.         printf("%s\n", strc);
  8.         return 0;
  9.     }
a) hello, world!!
b) Compile time error
c) Undefined behaviour
d) Segmenation fault
Answer: c
4. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         char *str = "hello, world\n";
  5.         str[5] = '.';
  6.         printf("%s\n", str);
  7.         return 0;
  8.     }
a) hello. world
b) hello, world
c) Compile error
d) Segmentation fault
Answer: d
5. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         char str[] = "hello, world";
  5.         str[5] = '.';
  6.         printf("%s\n", str);
  7.         return 0;
  8.     }
a) hello. world
b) hello, world
c) Compile error
d) Segmentation fault
Answer: a
6. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         char *str = "hello world";
  5.         char strary[] = "hello world";
  6.         printf("%d %d\n", sizeof(str), sizeof(strary));
  7.         return 0;
  8.     }
a) 11 11
b) 12 12
c) 4 12
d) 4 11
Answer: c
7. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         char *str = "hello world";
  5.         char strary[] = "hello world";
  6.         printf("%d %d\n", strlen(str), strlen(strary));
  7.         return 0;
  8.     }
a) 11 11
b) 12 11
c) 11 12
d) x 11 where x can be any positive integer.
Answer: a
8. What is the output of this C code?

  1.     #include 
  2.     void f(char *k)
  3.     {
  4.         k++;
  5.         k[2] = 'm';
  6.         printf("%c\n", *k);
  7.     }
  8.     void main()
  9.     {
  10.         char s[] = "hello";
  11.         f(s);
  12.     }
a) l
b) e
c) h
d) o
Answer: b
9. What is the output of this C code?

  1.     #include 
  2.     void fun(char *k)
  3.     {
  4.         printf("%s", k);
  5.     }
  6.     void main()
  7.     {
  8.         char s[] = "hello";
  9.         fun(s);
  10.     }
a) hello
b) Run time error
c) Nothing
d) h
Answer: a
10. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int ary[4] = {1, 2, 3, 4};
  5.         printf("%d\n", *ary);
  6.     }
a) 1
b) Compile time error
c) Some garbage value
d) Undefined variable
Answer: a
11. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         const int ary[4] = {1, 2, 3, 4};
  5.         int *p;
  6.         p = ary + 3;
  7.         *p = 5;
  8.         printf("%d\n", ary[3]);
  9.     }
a) 4
b) 5
c) Compile time error
d) 3
Answer: b
12. Different ways to initialize an array with all elements as zero are

a) int array[5] = {};
b) int array[5] = {0};
c) int a = 0, b = 0, c = 0;
    int array[5] = {a, b, c};
d) All of the mentioned
Answer: d
13. The elements in the array of the following code are
    int array[5] = {5};

a) 5, 5, 5, 5, 5
b) 5, 0, 0, 0, 0
c) 5, (garbage), (garbage), (garbage), (garbage)
d) (garbage), (garbage), (garbage), (garbage), 5
Answer: b
14. Which of the following declaration is illegal?
a) int a = 0, b = 1, c = 2;
    int array[3] = {a, b, c};
b) int size = 3;
    int array[size];
c) int size = 3;
    int array[size] = {1, 2, 3};
d) All of the mentioned
Answer: c
15. An array of similar data types which themselves are collection of dissimilar data type are
a) Linked Lists
b) Trees
c) Array of Structure
d) All of the mentioned
Answer: c
16. Comment on an array of void data type:
a) It can store any data-type
b) It only stores element of similar data type to first element
c) It acquires the data type with the highest precision in it
d) You cannot have an array of void data type
Answer: d
17. What is the output of the code given below?
  1.     #include 
  2.     int main()
  3.     {
  4.         int ary[4] = {1, 2, 3, 4};
  5.         int p[4];
  6.         p = ary;
  7.         printf("%d\n", p[1]);
  8.     }
a) 1
b) Compile time error
c) Undefined behaviour
d) 2
Answer: b

Related

Multiple Choice Questions 7407637979829754962

Post a Comment

emo-but-icon

item