250+ TOP MCQs on Character Pointers and Functions and Answers

C Objective Questions on “Character Pointers and Functions”. One shall practice these Objective Questions to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C Objective Questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C Objective Questions on “Character Pointers and Functions” along with answers, explanations and/or solutions:

1. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         char *str = "hello, worldn";
  5.         char *strc = "good morningn";
  6.         strcpy(strc, str);
  7.         printf("%sn", strc);
  8.         return 0;
  9.     }

a) hello, world
b) Crash/segmentation fault
c) Undefined behaviour
d) Run time error
Answer: b
Clarification: None.

2. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         char *str = "hello world";
  5.         char strc[] = "good morning indian";
  6.         strcpy(strc, str);
  7.         printf("%sn", strc);
  8.         return 0;
  9.     }

a) hello world
b) hello worldg india
c) Compile time error
d) Undefined behaviour
Answer: a
Clarification: None.

3. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         char *str = "hello, world!!n";
  5.         char strc[] = "good morningn";
  6.         strcpy(strc, str);
  7.         printf("%sn", strc);
  8.         return 0;
  9.     }

a) hello, world!!
b) Compile time error
c) Undefined behaviour
d) Segmenation fault
Answer: c
Clarification: None.

4. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         char *str = "hello, worldn";
  5.         str[5] = '.';
  6.         printf("%sn", str);
  7.         return 0;
  8.     }

a) hello. world
b) hello, world
c) Compile error
d) Segmentation fault
Answer: d
Clarification: None.

5. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         char str[] = "hello, world";
  5.         str[5] = '.';
  6.         printf("%sn", str);
  7.         return 0;
  8.     }

a) hello. world
b) hello, world
c) Compile error
d) Segmentation fault
Answer: a
Clarification: None.

6. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         char *str = "hello world";
  5.         char strary[] = "hello world";
  6.         printf("%d %dn", sizeof(str), sizeof(strary));
  7.         return 0;
  8.     }

a) 11 11
b) 12 12
c) 4 12
d) 4 11
Answer: c
Clarification: None.

7. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         char *str = "hello world";
  5.         char strary[] = "hello world";
  6.         printf("%d %dn", 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
Clarification: None.

8. What will be the output of the following C code?

  1.     #include 
  2.     void f(char *k)
  3.     {
  4.         k++;
  5.         k[2] = 'm';
  6.         printf("%cn", *k);
  7.     }
  8.     void main()
  9.     {
  10.         char s[] = "hello";
  11.         f(s);
  12.     }

a) l
b) e
c) h
d) o
Answer: b
Clarification: None.

9. What will be the output of the following 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
Clarification: None.

Leave a Reply

Your email address will not be published. Required fields are marked *