You can read integers of long long with %lld specifier via scanf() if your compiler and standard library supports that, but it is not guaranteed to be 64bit. (long long can store at least numbers between -9223372036854775807 (-(2**63 - 1)) and +9223372036854775807 (2**63 - 1) (both inclusive), so it should be at least 64bit)
You can use int64_t type and "%" SCNd64 format specifier from inttypes.h if it is supported in your environment. int64_t is a signed integer type with exactly 64bit.
You can use uint64_t type and "%" SCNu64 format specifier for unsigned 64-bit integer.
Example:
#include <stdio.h>
#include <inttypes.h>
int main(void) {
int64_t num;
if (scanf("%" SCNd64, &num) != 1) { /* read 64-bit number */
puts("read error");
return 1;
}
printf("%" PRId64 "\n", num); /* print the number read */
return 0;
}
You can read integers of
long longwith%lldspecifier viascanf()if your compiler and standard library supports that, but it is not guaranteed to be 64bit. (long longcan store at least numbers between-9223372036854775807(-(2**63 - 1)) and+9223372036854775807(2**63 - 1) (both inclusive), so it should be at least 64bit)You can use
int64_ttype and"%" SCNd64format specifier frominttypes.hif it is supported in your environment.int64_tis a signed integer type with exactly 64bit. You can useuint64_ttype and"%" SCNu64format specifier for unsigned 64-bit integer.Example: