char c; /* getchar is a function that reads a single character from the standard input stream stdin, regardless of what it is, and returns it to the program*/
c=getchar(); /* Single character from stdin is assigned to c variable */
printf("%d",c); /* %d tells printf that the corresponding argument is to be treated as an integer value; the type of the corresponding argument must be int. If we check ASCII value of 2 it is 50. */
NOTE: If you type printf("%c",c); then it will print the character which is assigned to variable c i.e, input = 2 and output = 2
EDIT : for more information on ASCII click here and on standard streams click here.