Codeforces and Polygon may be unavailable from December 6, 19:00 (UTC) to December 6, 21:00 (UTC) due to technical maintenance. ×

Error when using scanf "%d" then "%s".

Revision en1, by ContestDestroyer, 2017-10-05 22:36:52

A guy gave me this code:

#include<stdio.h>
#include<conio.h>
void main(void)
{
    int b;
    char a;
    scanf("%d",&b);
    scanf("%s",&a);
    printf("%d",b);
    getch();
}

I knew that he used the wrong specifier for char a, but this code ran, and after that, b's value that i had typed before was changed to another value. I'm very curious about this case, can someone show me how this is done?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English ContestDestroyer 2017-10-05 22:36:52 471 Initial revision (published)