Update for editable question :
Include the command line argument in quotation marks:
$ a.out "a\=b="
The quotes do not allow the shell to interpret the shell argument, so this string is passed to your program. I am using csh / bash ..works with both.
Alternatively, you can "escape" from \ with another and skip double quotes:
$ a.out a\\=b=
Previous answer to the original question :
Yes, use two \ :
char a[]="a\\=b=";
outputs:
a\=b=
Explanation
\ is an escape character used to indicate a special sequence of characters, therefore, for example, \t indicates a tab. If you want to actually print \t , you need to "avoid" this \ with another \ . See this example and conclusion:
printf("\t-->Hi\n"); /* print regular tab via \t */ printf("\\t-->Hi\n"); /* want to print "\t", not tab ..so we use two \\ */
that leads to:
-->Hi \t-->Hi
This is not unique to the printf() function and not to C, whether languages ββcan use backslashes to indicate "escape sequences" in strings.
Levon source share