C scanf behaving randomly

Правка en4, от PoustouFlan, 2022-09-17 01:30:05

Hello, codeforces!

As I am currently learning C in my computer science classes, I was thinking about trying to solve fundamental 800-1000 problems in C in codeforces.

But... I have no idea why this is happening :

#include <stdio.h>

int main()
{
    size_t n;
    scanf("%zu", &n);
    printf("%zu", n);
}

As a custom invocation, if you give 1 as input, it gives you 2 as output. It gave me random values in other contexts. It seems to behave fine when I use "%ld" instead of "%zu".

Any idea why this happens?

Теги c language, compiler, scanf, format

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en4 Английский PoustouFlan 2022-09-17 01:30:05 182
en3 Английский PoustouFlan 2022-09-16 13:57:49 205
en2 Английский PoustouFlan 2022-09-15 18:30:06 6 Tiny change: 'vocation, it is giving `1' -> 'vocation, giving `1'
en1 Английский PoustouFlan 2022-09-15 18:29:23 565 Initial revision (published)