I’m having trouble storing an integer

Asked

Viewed 15 times

0

#include <stdio.h>

int main()
{
    unsigned long long num = 1073741824;

    printf("num: %d\n", num);
    printf("num * 2: %d\n", num * 2);
    printf("num * 4: %d\n", num * 4);
    return 0;
}

inserir a descrição da imagem aqui

With this code the number will be printed in the 1st print, in the 2nd it will be negative and in the 3rd it Zera.

In the problem I need to store a value greater than 2 33

  • The %d is for numbers with signs, no? The correct would not be %u for unsigned?

  • 2

    Use the formatter "%llu"

  • 1

    @Augustovasques Oh, yes! Great, I just read this :) ps: maybe related https://stackoverflow.com/a/6400404/1518921

  • 1

    Orcboolg I think the table will help https://www.cplusplus.com/reference/cstdio/printf/ cc @Augustovasques

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.