Exercise (a) In inputting and outputting the name, you were asked NOT to use a b
ID: 3713317 • Letter: E
Question
Exercise (a) In inputting and outputting the name, you were asked NOT to use a bracketed subscript. Why is a bracketed subscript unnecessary? (b) Would using name(pos] work for inputting the name? Why or why not? (c) Would using name[pos] work for outputting the name? Why or why not? Try them both and b)? llyou don't need braces because you are using pointers. #include using namespace std; const int MAXNAME 10 int main) nt pos char name; int one int*two: nt three nt result; Il Fill in code to allocate the integer variable one here one-new int] W Fill in code to allocate the integer variable two here two new int 1]: W Fill in code to allocate the integer variable three here three new int[1] W Fill in code to allocate the character array pointed by name name-new charíMAXNAME coutExplanation / Answer
a) When we are inputting and outputting in pointer we should not use [] brackets because they are used when we are inputting or outputting the name using array and we have a fixed size of array. But we are declaring pointer we do not have a size we are referencing the value.
b) When inputting the name name[pos] it will result in segmentation fault which is also called core dump this takes place when a piece of code tries to do read and write operation in a read only location in memory or freed block of memory, it is an error indicating memory corruption.
c) When outputting the same using name[pos] it will also result in segmentation fault or core dump.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.