+ 2

What is output and why????

Q1 Cout<<"\\"; a ) \ b )\\ Q2 cout<<"\"; a ) \ b) error

6th Aug 2020, 6:11 PM
Learner
Learner - avatar
3 ответов
+ 5
Inside a quoted string, the backslash character is used as a delimiter to start an escape sequence which consists of the backslash character itself and an additional character. This means that if you want to print the backslash character, you have to escape it itself, which is what is happening in Q1. Here, the first '\' starts the escape sequence, and then the second '\' is actually embedded in the string, resulting in output a). Otherwise, the next character belongs to the sequence, which in Q2 is ". You use the sequence \" to print the quote character which otherwise would end the string. However, now that the second " is escaped, it no longer terminates the string, resulting in an error due to a missing double quote.
6th Aug 2020, 6:33 PM
Shadow
Shadow - avatar
+ 4
q1 a q2 error since \ it is pecial symbol to specify \n enter \t tab and etc . and if you want use this aymbol as char literal you need to ad \\.
6th Aug 2020, 6:25 PM
george
george - avatar
+ 1
Q1-A Q2-B
6th Aug 2020, 10:37 PM
Gabriel Caldeira Bicalho
Gabriel Caldeira Bicalho - avatar