Why only one backslash is getting printed? And when I try to put only one backslash in the 2nd elrment of array, I get an error. | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
0

Why only one backslash is getting printed? And when I try to put only one backslash in the 2nd elrment of array, I get an error.

https://code.sololearn.com/cBvFJ9FOqRzH/?ref=app

12th Oct 2020, 12:40 PM
Prasenjit Kumar
Prasenjit Kumar - avatar
3 Respuestas
+ 1
Backslash is supposed to be a terminating character in programming. Anything after that will have another meaning: For example \n will add a new line, also the n will not be displayed. Same happens here \\ the first backslash removes the second backslash like in the above example. There is no actual use of this like that of \n.
12th Oct 2020, 12:45 PM
Steve Sajeev
Steve Sajeev - avatar
+ 1
Oh! now i see. Thanks
12th Oct 2020, 12:50 PM
Prasenjit Kumar
Prasenjit Kumar - avatar
0
Backslash is special characters used in escape sequence. So to put you need '\\' like this,.. On encountering \, compiler treats that a special characters and it works as on depending on the next charecter.. Ex: \n =>new line \t =>tab, \\ =>backslash
12th Oct 2020, 12:47 PM
Jayakrishna 🇮🇳