C Control StatementsC FunctionsC ArrayC PointerC Dynamic MemoryC StringC MathC StructureC UnionC File HandlingC PreprocessorC Command LineC Misc |
string interview questions
printf(“%c”, *++p); |
int main() |
a. H
b. Happy
c. Happy\0
d. None of these
The correct option is (a)
Explanation:
Adding a NULL or \0 at the end is a correct way of representing a C string. You can simple use char str[]=”Happy”. It is same as above.
4. How do you convert char array to string.?
char strg[]={‘S’,’m’,’i’,’l’,’e’};
a. strg[5]=’\0′;
b. strg[]={“S”,”m”,”i”,”l”,”e”,’\0′};
c. strg[5]=0;
d. All of above
correct option d(All of above)
5. What is the output of the following program ?
int main() |
a) N N N
b) N Ng Ng
c) N*randomchar* Ng Ng
d) Compiler error
Explanation:
Notice that strg is not a string as it is not a char array with null at the end. So strg is the address of array which is converted to Char by %c. If you use %s, it prints the first number converted to char.
6. What is the output of C program with strings.?
int main() |
a) Lovely
b) L
c) Lovely\0
d) Compiler error
correct option d
Explanation:
You can not assign one string to the other. It is an error. ”
7. What is the output of C Program with arrays.?
int main() |
a. Delhi
b. New Delhi
c. New
d. Compiler error
correct option C
Explanation:
SCANF can not accept a string with spaces or tabs. So SCANF takes only New into STR.