This set of C Multiple Choice Questions & Answers (MCQs) focuses on “String Operations – 1”.
Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.
1. What will be the output of the following C code?
#include <stdio.h>
#include <string.h>
int main()
{
char *str = "hello, world";
char *str1 = "hello, world";
if (strcmp(str, str1))
printf("equal");
else
printf("unequal");
}
a) equal
b) unequal
c) Compilation error
d) Depends on the compiler
View Answer
Explanation: None.
2. What will be the output of the following C code?
#include <stdio.h>
int main()
{
char *str = "hello, world";
char str1[15] = "hello wo 9";
strcpy(str, str1);
printf("%s", str1);
}
a) Compilation error
b) Segmentation Fault
c) hello, world
d) hello, wo 9
View Answer
Explanation: None.
3. What will be the output of the following C code?
#include <stdio.h>
#include <string.h>
int main()
{
char *str = "hello, world";
char str1[9];
strncpy(str1, str, 9);
printf("%s %d", str1, strlen(str1));
}
a) hello, world 11
b) hello, wor 9
c) Undefined behaviour
d) Compilation error
View Answer
Explanation: None.
4. What will be the output of the following C code?
#include <stdio.h>
int main()
{
char *str = "hello, world\n";
printf("%d", strlen(str));
}
a) Compilation error
b) Undefined behaviour
c) 13
d) 11
View Answer
Explanation: None.
5. What will be the output of the following C code?
#include <stdio.h>
int main()
{
char str[11] = "hello";
char *str1 = "world";
strcat(str, str1);
printf("%s %d", str, str[10]);
}
a) helloworld 0
b) helloworld anyvalue
c) worldhello 0
d) Segmentation fault/code crash
View Answer
Explanation: None.
6. Strcat() function adds null character.
a) Only if there is space
b) Always
c) Depends on the standard
d) Depends on the compiler
View Answer
Explanation: None.
7. What will be the output of the following C code?
#include <stdio.h>
int main()
{
char str[10] = "hello";
char *str1 = "world";
strncat(str, str1, 9);
printf("%s", str);
}
a) helloworld
b) Undefined behaviour
c) helloworl
d) hellowor
View Answer
Explanation: None.
Sanfoundry Global Education & Learning Series – C Programming Language.
To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Practice BCA MCQs
- Apply for C Internship
- Practice Computer Science MCQs
- Buy Computer Science Books
- Watch Advanced C Programming Videos