Questions tagged [long-long]

The `long long` size modifier was introduced in C++11 and can be used with integral types to select an integer of at least 64 bits.

See cppreference for more information.

131 questions
462
votes
14 answers

How do you format an unsigned long long int using printf?

#include int main() { unsigned long long int num = 285212672; //FYI: fits in 29 bits int normalInt = 5; printf("My number is %d bytes wide and its value is %ul. A normal number is %d.\n", sizeof(num), num, normalInt); …
andrewrk
  • 30,272
  • 27
  • 92
  • 113
45
votes
3 answers

Should I use long long or int64_t for portable code?

I have an open-source codebase that is written in both C and C++. I'm looking for an integer type that is guaranteed to be at least 64 bits wide, which can be reliably compiled on most OS X (Intel, 64-bit) and Linux boxes with open-source C and C++…
Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
38
votes
2 answers

What kind of data type is "long long"?

I don't know this type. Is that the biggest one from all? I think it is an integer type, right? Or is it a floating point thing? Bigger than double?
openfrog
  • 40,201
  • 65
  • 225
  • 373
38
votes
1 answer

Is C++11's long long really at least 64 bits?

It says on wikipedia and in Stroustrup's FAQ that type long long is at least as long as an int and has no fewer than 64 bits. I have been looking at the C++11 standard §3.9.1 Fundamental Types section and I cannot find any reference to 64 bits. All…
juanchopanza
  • 223,364
  • 34
  • 402
  • 480
31
votes
3 answers

Why is my arithmetic with a long long int behaving this way?

I'm trying to calculate large integers with the long long datatype but when it gets large enough (2^55), the arithmetic behavior is unpredictable. I am working in Microsoft Visual Studio 2017. In this first case, I am subtracting 2 from the long…
Edvin K
  • 329
  • 3
  • 5
23
votes
3 answers

Why is the use of cin, cout or %I64d preferred over %lld specifier in C++?

Why do many of the online judges advise "do not use the %lld specifier to read or write 64-bit integers in С++"? Is it preferred to use the cin, cout streams or the %I64d specifier?
Rishabh
  • 730
  • 2
  • 11
  • 25
22
votes
4 answers

sprintf for unsigned _int64

I am having following code. output of second %d in sprintf is always shown as zero. I think i am specifying wrong specifiers. Can any one help me in getting write string with right values. And this has to achieved in posix standard. Thanks for…
venkysmarty
  • 11,099
  • 25
  • 101
  • 184
22
votes
4 answers

How do I check if A+B exceed long long? (both A and B is long long)

I have two numbers: A and B. I need to calculate A+B somewhere in my code. Both A and B are long long, and they can be positive or negative. My code runs wrong, and I suspect the problem happens when calculating A+B. I simply want to check if A+B…
abcdabcd987
  • 2,043
  • 2
  • 23
  • 34
16
votes
1 answer

Convert long long to string in C?

I'd like to convert a long long to a string in C. long long x = 999; I'd like to convert x to a string. How could I go about doing that? Thanks.
Tommy
  • 965
  • 6
  • 13
  • 21
15
votes
2 answers

"Int" multiplication in c++ with "long long" result

I am trying to find the square of a int. My code looks like below: long long sqr=0; int num=77778; sqr= num*num; The result should have been 6049417284 But when I check the output it shows 1754449988. What is the mistake I am doing? long long…
srip
  • 617
  • 1
  • 6
  • 18
11
votes
7 answers

Why do C compilers specify long to be 32-bit and long long to be 64-bit?

Wouldn't it have made more sense to make long 64-bit and reserve long long until 128-bit numbers become a reality?
sj755
  • 3,944
  • 14
  • 59
  • 79
10
votes
5 answers

long long value in Visual Studio

We know that -2*4^31 + 1 = -9.223.372.036.854.775.807, the lowest value you can store in long long, as being said here: What range of values can integer types store in C++. So I have this operation: #include unsigned long long…
Peter
  • 337
  • 2
  • 12
9
votes
4 answers

How to loop bit by bit over a long long in C++

If I have long long x; in c++, how can I loop over each bit in the number to check if it zero or 1? I would like to count the number of ones in the bits.
Mohamed Naguib
  • 1,720
  • 6
  • 23
  • 32
8
votes
5 answers

Long long in c99

In the C99 standard they introduced long long. What is the purpose of this? In my (limited) C programming experience, I've only every seen a 4-byte int and an 8-byte long. For example, from Compiler Explorer: If long is already 8 then, why is it…
carl.hiass
  • 1,526
  • 1
  • 6
  • 26
8
votes
3 answers

Printing bits in long long number (C++)

I want to print all bits of a long long number. When I am doing it in main() everything is fine, but in printBits() function (where code is same) there is an extra 1 on 32th bit. The code: #include void printBits(long long number) { …
1
2 3
8 9