MCQ-4 String
MCQ-4 String
MCQ-4 Strings
{
const char *p="hello";
cout<<*&*&p;
return 0;
}
A. llo
B. hello
C. ello
D. h
7. In CPP, the size of the character array should be one larger than the number of
characters in the string.
a. True
b. False
Page (3/7)
{
char *temp = str1;
str1 = str2;
str2 = temp;
}
int main()
{
char *str1 = "Matrix";
char *str2 = "Computer";
swap(str1, str2);
printf("str1 is %s, str2 is %s", str1, str2);
return 0;
}
a. str1 is Computer, str2 is Matrix
b. str1 is Matrix, str2 is Computer
c. str1 is Matrix, str2 is Matrix
d. str1 is Computer, str2 is Computer
13. #include<stdio.h>
int main()
{
char str[] = "GeeksQuiz";
printf("%s %s %s\n",&str[5],&5[str], str+5);
printf("%c %c %c\n",*(str+6),str[6], 6[str]);
return 0;
}
a. Runtime Error
b. Compiler Error
c. uiz uiz uiz u u u
d. Quiz Quiz Quiz u u u
14. In below program, what would you put in place of “?” to print “Quiz”?
#include <stdio.h>
Page (5/7)
int main()
{
char arr[] = "GeeksQuiz";
printf("%s", ?);
return 0;
}
a. arr
b. (arr+5)
c. (arr+4)
d. Not possible
Output?
a. ziuqskeeg
b. Nothing is printed on the screen
c. geeksquiz
d. gggggggg
19. Predict the output of following program, assume that a character takes 1 byte and
pointer takes 4
bytes.
#include <stdio.h>
int main()
{
char *str1 = "GeeksQuiz";
char str2[] = "GeeksQuiz";
21. If the two strings are identical, then strcmp() function returns
Page (7/7)
A. -1
B. 1
C. 0
D. Yes
22. The library function used to find the last occurrence of a character in a string is
A. strnstr()
B. laststr()
C. strrchr()
D. strstr()
23. Which of the following function is used to find the first occurrence of a given string
in another string?
A. strchr()
B. strrchr()
C. strstr()
D. strnset()