Ultra fast mathematician


why is this format wrong? Please don’t send the corrected code instead please explain why this format of string operation is wrong? " i want to know concept".

hello @nirupama1
your s3 string is empty string and u cannot do something like s3[i]=‘1’ or s3[i]=‘0’ becuase it is empty string.
to do this operation upto n-1 index ur s3 size should be n.
so declare s3 as string of size n and then apply the same operation.

1 Like

but when we declare strings ,without any size specified, to take some input it is also empty here . but when we give input it assigns the characters at their indices. why is this not an issue there?

see
if s is empty string then this operation
s=some other string is allowed.(here it is similar to construct a new building)

but if we do s[i] with empty string then it is not allowed ( it is something like go to ith floor of the building but the building is itself not existing).

so we have to make a character array here we cannot use string?

u can do something like
string s3(n,’ '); // this will construct building with n floors

this is the only change u need to do in ur code.