How to add large negative integers?

following code prints me 2 instead of -4294967294. Is there any way to add such negative integers?

1
2
3
4
5
6
7
8
9
10
#include <stdio.h>

int main()
{
    signed long long int varname;
    varname = -4294967295;
    varname +=1;
    printf("%lli",varname);
    return 0;
}
Hi there,

the problem is that the length of the constant exceeds the limits of a signed integer, if you ad the LL postfix to the value it runs fine.
 
varname = -4294967295LL;

I hope this helps,

Phil.
1
2
3
4
5
6
7
8
9
10
#include <stdio.h>

int main()
{
    signed long long int varname;
    varname = -4294967295LL;
    varname +=1;
    printf("%LLd",varname);
    return 0;
}


still returns 2
Hi there,

That would be because the code you just posted is different from the one that you posted originally. You have changed the following line from this:
 
printf("%lli",varname);

to this:
 
printf("%LLd",varname);

If you change it back it runs perfectly fine.

Many thanks,

Phil.
Following code returns me 2
1
2
3
4
5
6
7
8
9
10
#include <stdio.h>

int main()
{
    signed long long int varname;
    varname = -4294967295LL;
    varname +=1;
    printf("%LLd",varname);
    return 0;
}
Last edited on
also this doesnt work,
1
2
3
4
5
6
7
8
9
10
#include <stdio.h>

int main()
{
    signed long long int varname;
    varname = -4294967295LL;
    varname +=1LL;
    printf("%LLd",varname);
    return 0;
}
Try this: printf("%lld",varname); // notice the lowercase ll instead of LL
still 2.

Why dont you guys test solution before you post it.
Hi there,

I appreciate that you might find it frustrating but I did test the solution before I posted - as I always do. Both Null and myself have advised you of the solution to your problem - in your previous post you still had not made the changes that we had told you about.

I would advise you to re-read this entire thread before making comments like the one above - otherwise you might find that people will not help you in future.

Regards,

Phil.
Look my last code, it got all changes, I added LL and also tried ll as null said.
Topic archived. No new replies allowed.