Question: explain this: Differences string str (def) ; char ch; ch = str . at (2) ; / / ch is 'f' now str. at (0)

explain this:

explain this: Differences string str ("def") ;
Differences string str ("def") ; char ch; ch = str . at (2) ; / / ch is 'f' now str. at (0) = str. at (1) ; / / str is "eef" now How do these differ? . - if index is valid, undefined behavior results . E.g., if we ask for str[10] . at is "safer" - it will throw an exception if the index is out-of-bounds (An exception is a detected runtime error that commonly prints an error message and terminates the program.) . Usage examples: . How can we output each character in a string in a single vertical column? . How can we output each character in a string from back to front? . Accessing strings by index in a loop is a common operation

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Law Questions!