Why do '?' and '/?' give the same output in C?

  • A+
Category:Languages

In C, why do these two pieces of code give the same output?

#include<stdio.h>  int main(void) {     const char c='/?';     printf("%c",c); } 

and

#include<stdio.h>  int main(void) {     const char c='?';     printf("%c",c); } 

I understand that a backslash is used to make quotes (" or ') and a backslash obvious to the compiler when we use printf(), but why does this work for the '?'?


/? is an escape sequence exactly equivalent to ?, and is used to escape trigraphs:

#include <stdio.h> int main(void) {     printf("%s %s", "??=", "?/?="); // output is # ??= } 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: