C++ Programming Multiple Choice Questions & Answers (MCQs) on “String – 1”.
Provera works by suppressing the body's natural testosterone. The american heart association's (aha) get with the guidelines-for clinical practice guidelines (cpg) for chronic fatigue syndrome (cfs) is the result of 18 months of work Georgia http://raygungothicrocket.com/join-the-adventure by an international team of experts who reviewed the available medical literature and used their clinical knowledge to arrive at a comprehensive overview of the evidence and what we know about cfs and its treatment. The dose of the medication should be increased in the future if the person’s acne is not improving.
Abnormal bleeding (vomiting, spotting or bleeding in the vaginal canal or anus) It is http://byoungco.com/products/b425-stinghd buy stromectol 3 mg recommended to take the treatment for 6 months or 1 year. You have probably decided that the new place suits you much better than where you've been living for the past couple of years.
1. What is string objects in C++?
a) Stream of alphabets
b) A stream of well-defined characters
c) Stream of characters
d) A stream of characters terminated by
Answer: b
Clarification: String is defined as streams of characters, not necessarily terminated by . Also, a string can contain characters other than alphabets.
2. What is Character-Array?
a) array of alphabets
b) array of well-defined characters
c) array of characters
d) array of characters terminated by
Answer: c
Clarification: Character-Array is defined as an array of characters, not necessarily terminated by . Also, a character-array can contain characters other than alphabets.
3. Pick the incorrect statement about Character-Array.
a) Character-Array can be terminated by a null character(‘ ’)
b) Character-Array has a static size
c) Character-Array has a dynamic size
d) Character-Array has a threat of array-decay
Answer: c
Clarification: As Character-Array is an array, its size should be defined during its declaration hence the size of Character-Array is static. A Character-Array is not necessarily to be terminated by a null character. Also, it has a threat of array-decay.
4. Pick the correct statement about string objects in C++.
a) String objects must be terminated by a null character(‘ ’)
b) String objects have a static size
c) String objects have a dynamic size
d) String objects use extra memory than required.
Answer: c
Clarification: String objects are dynamic in nature i.e. their size varies as their value changes so they don’t use any extra memory and it is not necessary to terminate a string object by ‘ ’.
5. What will be the output of the following C++ code?
#include#include using namespace std; int main(int argc, char const *argv[]) { string str; cin>>str; cout<<str; return 0; }
a) str
b) Input provided by the user
c) Error
d) Segmentation fault
Answer: b
Clarification: There is no error in the program and as we are asking the user to enter a string and printing that string to console. Therefore output will be the string provided by the user.
6. What will be the output of the following C++ code?
#include#include using namespace std; int main(int argc, char const *argv[]) { char str[] = "Hello World"; cout<<str[0]; return 0; }
a) H
b) e
c) Error
d) o
Answer: a
Clarification: The program has no errors so and as str = “Hello World” and we are trying to print the first character of str. Hence “H” is the answer.
7. What will be the output of the following C++ code?
#include#include using namespace std; int main(int argc, char const *argv[]) { char str[10]; cin>>str; cout<<str; return 0; }
a) Compiler-time Error
b) Run-time Error
c) Input given by the user
d) Depends on the length of the string entered by the user
Answer: d
Clarification: As the character array size is 10 so if the string entered by the user is 10 then the program gives a run-time error because the string crosses the allocated memory space.
Output:
length 10 $ ./a.out C++Programming *** stack smashing detected ***:terminated Aborted (core dumped)
8. What will be the output of the following C++ code if the string entered by the user is “Hello World”?
#include#include using namespace std; int main(int argc, char const *argv[]) { string str; cin>>str; cout<<str; return 0; }
a) Hello World
b) Hello
c) World
d) Error
Answer: b
Clarification: As cin considers n or space as the terminating symbols for the input so when the user enters “Hello World” so only “Hello” will be stored into the str variable as cin stops scanning input after space.
Output:
$ ./a.out Hello World Hello