C Strings MCQ
Q1) What is a String in C Language.?
- String is a new Data Type in C
- String is an array of Characters with null character as the last element of array.
- String is an array of Characters with null character as the first element of array
- String is an array of Integers with 0 as the last element of array.
Answer:- (B).
Explanations :none
Explanations :none
char ary[]="Hello..!";
- Character array, ary is a string.
- ary has no Null character at the end
- String size is not mentioned
- String can not contain special characters.
Answer:- (A).
Explanations :It is a simple way of creating a C String. You can also define it like the below. \0 is mandatory in this version. char ary[] = {'h','e','l','l','o','\0'};
Explanations :It is a simple way of creating a C String. You can also define it like the below. \0 is mandatory in this version. char ary[] = {'h','e','l','l','o','\0'};
- %c
- %C
- %s
- %w
Answer:- (C).
Explanations :char ary[]="Hello..!";
printf("%s",ary);
Explanations :char ary[]="Hello..!";
printf("%s",ary);
int main() { char ary[]="Discovery Channel"; printf("%s",ary); return 0; }
- D
- Discovery Channel
- Discovery
- Compiler error
Answer:- (B).
Explanations :%s prints the while character array in one go.
Explanations :%s prints the while character array in one go.
int main() { char str[]={'g','l','o','b','e'}; printf("%s",str); return 0; }
- g
- globe
- globe\0
- None of the above
Answer:- (D).
Explanations :Notice that you have not added the last character \0 in the char array. So it is not a string. It can not know the end of string. So it may print string with some garbage values at the end.
Explanations :Notice that you have not added the last character \0 in the char array. So it is not a string. It can not know the end of string. So it may print string with some garbage values at the end.
int main() { char str[]={'g','l','o','b','y','\0'}; printf("%s",str); return 0; }
- g
- globe
- globe\0
- Compiler error
Answer:- (B).
Explanations :Adding a NULL or \0 at the end is a correct way of representing a C string. You can simple use char str[]="globy". It is same as above.
Explanations :Adding a NULL or \0 at the end is a correct way of representing a C string. You can simple use char str[]="globy". It is same as above.
char str[]={'g','l','o','b','y'};
- str[5] = 0;
- str[5] = '\0'
- str[]={'g','l','o','b','y','\0'};
- All the above
Answer:- (D).
Explanations :none
Explanations :none
int main() { int str[]={'g','l','o','b','y'}; printf("A%c ",str); printf("A%s ",str); printf("A%c ",str[0]); return 0; }
- A A A
- A Ag Ag.
- A*randomchar* Ag Ag
- Compiler error.
Answer:- (C).
Explanations :Notice that STR is not a string as it is not a char array with null at the end. So STR is the address of array which is converted to Char by %c. If you use %s, it prints the first number converted to char.
Explanations :Notice that STR is not a string as it is not a char array with null at the end. So STR is the address of array which is converted to Char by %c. If you use %s, it prints the first number converted to char.
int main() { char str[]={"C","A","T","\0"}; printf("%s",str); return 0; }
- C
- CAT
- CAT\0
- Compiler error
Answer:- (D).
Explanations :Yes. You can not use Double Quotes " to represent a single character. Correct way is 'C' not "C". You should use Single Quotes around a single character constant.
Explanations :Yes. You can not use Double Quotes " to represent a single character. Correct way is 'C' not "C". You should use Single Quotes around a single character constant.
- 32 characters
- 64 characters
- 256 characters
- None of the above
Answer:- (D).
Explanations :Maximum size of a C String is dependent on implemented PC memory. C does not restrict C array size or String Length.
Explanations :Maximum size of a C String is dependent on implemented PC memory. C does not restrict C array size or String Length.
Copyright © 2022 Shineskill Software Pvt. Ltd., All rights reserved.