#include <stdio.h>
int main(void) {
char ch,ch1;
scanf("%c",&ch);/*input ab here*/
scanf("%c",&ch1);
printf("%c %c",ch,ch1);
return 0;
}
Why this produces a b as output. We don't enter any input for second variable but it still got assigned. Could anyone explain the behavior.
You can check the output here if you want.
"%c"scans one byte of input, which consumesa, andbis still in the input stream when the secondscanf()gets called. That's just howscanf()works.%cdoesn't skip blank lines.char? That's what the question title looks like. I haven't messed around with<stdio.h>because I use C++ and<iostream>, but%clooks like, at a glance, the syntax to represent acharin<stdio.h>. Correct me if I'm wrong, please. :)