How to read and assign big integers in C?












0















I am trying to assign big integer value to a variable in c and when I print I only get 10123456.



What is the issue?



  int main(){
long a = 1234567890123456;
printf("n",sizeof(a));
printf("%ld",a);
}









share|improve this question




















  • 7





    long isn't that long, try long long

    – harold
    Aug 20 '13 at 9:47






  • 2





    What prints printf("n",sizeof(a)); ?

    – nouney
    Aug 20 '13 at 9:48











  • stackoverflow.com/questions/124332/…

    – Maroun
    Aug 20 '13 at 9:49











  • Use long long int or some compiler specific types like __int64 or int64_t.

    – bkausbk
    Aug 20 '13 at 9:51






  • 1





    @keltar: Look at the comment by nouney

    – Don't You Worry Child
    Aug 20 '13 at 10:18


















0















I am trying to assign big integer value to a variable in c and when I print I only get 10123456.



What is the issue?



  int main(){
long a = 1234567890123456;
printf("n",sizeof(a));
printf("%ld",a);
}









share|improve this question




















  • 7





    long isn't that long, try long long

    – harold
    Aug 20 '13 at 9:47






  • 2





    What prints printf("n",sizeof(a)); ?

    – nouney
    Aug 20 '13 at 9:48











  • stackoverflow.com/questions/124332/…

    – Maroun
    Aug 20 '13 at 9:49











  • Use long long int or some compiler specific types like __int64 or int64_t.

    – bkausbk
    Aug 20 '13 at 9:51






  • 1





    @keltar: Look at the comment by nouney

    – Don't You Worry Child
    Aug 20 '13 at 10:18
















0












0








0


1






I am trying to assign big integer value to a variable in c and when I print I only get 10123456.



What is the issue?



  int main(){
long a = 1234567890123456;
printf("n",sizeof(a));
printf("%ld",a);
}









share|improve this question
















I am trying to assign big integer value to a variable in c and when I print I only get 10123456.



What is the issue?



  int main(){
long a = 1234567890123456;
printf("n",sizeof(a));
printf("%ld",a);
}






c






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 7 '15 at 8:43









TryinHard

2,88122143




2,88122143










asked Aug 20 '13 at 9:46







user2684719















  • 7





    long isn't that long, try long long

    – harold
    Aug 20 '13 at 9:47






  • 2





    What prints printf("n",sizeof(a)); ?

    – nouney
    Aug 20 '13 at 9:48











  • stackoverflow.com/questions/124332/…

    – Maroun
    Aug 20 '13 at 9:49











  • Use long long int or some compiler specific types like __int64 or int64_t.

    – bkausbk
    Aug 20 '13 at 9:51






  • 1





    @keltar: Look at the comment by nouney

    – Don't You Worry Child
    Aug 20 '13 at 10:18
















  • 7





    long isn't that long, try long long

    – harold
    Aug 20 '13 at 9:47






  • 2





    What prints printf("n",sizeof(a)); ?

    – nouney
    Aug 20 '13 at 9:48











  • stackoverflow.com/questions/124332/…

    – Maroun
    Aug 20 '13 at 9:49











  • Use long long int or some compiler specific types like __int64 or int64_t.

    – bkausbk
    Aug 20 '13 at 9:51






  • 1





    @keltar: Look at the comment by nouney

    – Don't You Worry Child
    Aug 20 '13 at 10:18










7




7





long isn't that long, try long long

– harold
Aug 20 '13 at 9:47





long isn't that long, try long long

– harold
Aug 20 '13 at 9:47




2




2





What prints printf("n",sizeof(a)); ?

– nouney
Aug 20 '13 at 9:48





What prints printf("n",sizeof(a)); ?

– nouney
Aug 20 '13 at 9:48













stackoverflow.com/questions/124332/…

– Maroun
Aug 20 '13 at 9:49





stackoverflow.com/questions/124332/…

– Maroun
Aug 20 '13 at 9:49













Use long long int or some compiler specific types like __int64 or int64_t.

– bkausbk
Aug 20 '13 at 9:51





Use long long int or some compiler specific types like __int64 or int64_t.

– bkausbk
Aug 20 '13 at 9:51




1




1





@keltar: Look at the comment by nouney

– Don't You Worry Child
Aug 20 '13 at 10:18







@keltar: Look at the comment by nouney

– Don't You Worry Child
Aug 20 '13 at 10:18














3 Answers
3






active

oldest

votes


















6














Largest integer type is:



unsigned long long


dont forget about ULL suffix.

or if you need larger integers, take a look for some bigint libraries like gmp.



Of course, there is also long long, but it is also for negative integers and have smaller limits.



 Type                min                      max

(signed) long long -9223372036854775808 9223372036854775807
unsigned long long 0 18446744073709551615





share|improve this answer


























  • In C 1999 and later, the largest integer types described by the standard are intmax_t and uintmax_t. They are at least as large as unsigned long long and might be larger.

    – Eric Postpischil
    Aug 20 '13 at 13:08



















2














long a = 1234567890123456L;


If long is long enough, depends on compiler/OS. If not



long long a = 1234567890123456LL;





share|improve this answer































    0














    If the number is greater than 64-bit, i.e. longer than what unsigned long long can hold, then no data type in C other than string(char) will be able to accomodate that value, store it as a string & try writing your own functions to operate (e.g. add, subtract, etc.) on these "very large numbers".






    share|improve this answer


























    • There is no string in C

      – Zaffy
      Aug 20 '13 at 10:07






    • 1





      @Zaffy I know, that's why I wrote string(char), sorry for writing string as a code.

      – Don't You Worry Child
      Aug 20 '13 at 10:20











    • @Zaffy C11 7.1.1 1 "Definitions of terms. A string is a contiguous sequence of characters terminated by and including the first null character. ..."

      – chux
      Aug 20 '13 at 12:22






    • 1





      It is not generally true that an integer greater than what fits into 64 bits is not representable in some integer type in C. C 1999 and later provides for a variety of integer types, and an implementation may provide integer types of any size.

      – Eric Postpischil
      Aug 20 '13 at 13:09








    • 1





      @nishant: Clause 7.20 of the C standard describes the stdint.h headers, which describes types such as intmax_t and uintmax_t for integers of the greatest width in the implementation, along with types for specific widths, macros for writing constants of the various types, and other embellishments. The inttypes.h header in clause 7.8 provides format specifiers for using the types with printf.

      – Eric Postpischil
      Aug 20 '13 at 17:51













    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f18331913%2fhow-to-read-and-assign-big-integers-in-c%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown
























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    6














    Largest integer type is:



    unsigned long long


    dont forget about ULL suffix.

    or if you need larger integers, take a look for some bigint libraries like gmp.



    Of course, there is also long long, but it is also for negative integers and have smaller limits.



     Type                min                      max

    (signed) long long -9223372036854775808 9223372036854775807
    unsigned long long 0 18446744073709551615





    share|improve this answer


























    • In C 1999 and later, the largest integer types described by the standard are intmax_t and uintmax_t. They are at least as large as unsigned long long and might be larger.

      – Eric Postpischil
      Aug 20 '13 at 13:08
















    6














    Largest integer type is:



    unsigned long long


    dont forget about ULL suffix.

    or if you need larger integers, take a look for some bigint libraries like gmp.



    Of course, there is also long long, but it is also for negative integers and have smaller limits.



     Type                min                      max

    (signed) long long -9223372036854775808 9223372036854775807
    unsigned long long 0 18446744073709551615





    share|improve this answer


























    • In C 1999 and later, the largest integer types described by the standard are intmax_t and uintmax_t. They are at least as large as unsigned long long and might be larger.

      – Eric Postpischil
      Aug 20 '13 at 13:08














    6












    6








    6







    Largest integer type is:



    unsigned long long


    dont forget about ULL suffix.

    or if you need larger integers, take a look for some bigint libraries like gmp.



    Of course, there is also long long, but it is also for negative integers and have smaller limits.



     Type                min                      max

    (signed) long long -9223372036854775808 9223372036854775807
    unsigned long long 0 18446744073709551615





    share|improve this answer















    Largest integer type is:



    unsigned long long


    dont forget about ULL suffix.

    or if you need larger integers, take a look for some bigint libraries like gmp.



    Of course, there is also long long, but it is also for negative integers and have smaller limits.



     Type                min                      max

    (signed) long long -9223372036854775808 9223372036854775807
    unsigned long long 0 18446744073709551615






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Aug 20 '13 at 10:04

























    answered Aug 20 '13 at 9:50









    ZaffyZaffy

    12k83664




    12k83664













    • In C 1999 and later, the largest integer types described by the standard are intmax_t and uintmax_t. They are at least as large as unsigned long long and might be larger.

      – Eric Postpischil
      Aug 20 '13 at 13:08



















    • In C 1999 and later, the largest integer types described by the standard are intmax_t and uintmax_t. They are at least as large as unsigned long long and might be larger.

      – Eric Postpischil
      Aug 20 '13 at 13:08

















    In C 1999 and later, the largest integer types described by the standard are intmax_t and uintmax_t. They are at least as large as unsigned long long and might be larger.

    – Eric Postpischil
    Aug 20 '13 at 13:08





    In C 1999 and later, the largest integer types described by the standard are intmax_t and uintmax_t. They are at least as large as unsigned long long and might be larger.

    – Eric Postpischil
    Aug 20 '13 at 13:08













    2














    long a = 1234567890123456L;


    If long is long enough, depends on compiler/OS. If not



    long long a = 1234567890123456LL;





    share|improve this answer




























      2














      long a = 1234567890123456L;


      If long is long enough, depends on compiler/OS. If not



      long long a = 1234567890123456LL;





      share|improve this answer


























        2












        2








        2







        long a = 1234567890123456L;


        If long is long enough, depends on compiler/OS. If not



        long long a = 1234567890123456LL;





        share|improve this answer













        long a = 1234567890123456L;


        If long is long enough, depends on compiler/OS. If not



        long long a = 1234567890123456LL;






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Aug 20 '13 at 9:50









        keltarkeltar

        12.5k12534




        12.5k12534























            0














            If the number is greater than 64-bit, i.e. longer than what unsigned long long can hold, then no data type in C other than string(char) will be able to accomodate that value, store it as a string & try writing your own functions to operate (e.g. add, subtract, etc.) on these "very large numbers".






            share|improve this answer


























            • There is no string in C

              – Zaffy
              Aug 20 '13 at 10:07






            • 1





              @Zaffy I know, that's why I wrote string(char), sorry for writing string as a code.

              – Don't You Worry Child
              Aug 20 '13 at 10:20











            • @Zaffy C11 7.1.1 1 "Definitions of terms. A string is a contiguous sequence of characters terminated by and including the first null character. ..."

              – chux
              Aug 20 '13 at 12:22






            • 1





              It is not generally true that an integer greater than what fits into 64 bits is not representable in some integer type in C. C 1999 and later provides for a variety of integer types, and an implementation may provide integer types of any size.

              – Eric Postpischil
              Aug 20 '13 at 13:09








            • 1





              @nishant: Clause 7.20 of the C standard describes the stdint.h headers, which describes types such as intmax_t and uintmax_t for integers of the greatest width in the implementation, along with types for specific widths, macros for writing constants of the various types, and other embellishments. The inttypes.h header in clause 7.8 provides format specifiers for using the types with printf.

              – Eric Postpischil
              Aug 20 '13 at 17:51


















            0














            If the number is greater than 64-bit, i.e. longer than what unsigned long long can hold, then no data type in C other than string(char) will be able to accomodate that value, store it as a string & try writing your own functions to operate (e.g. add, subtract, etc.) on these "very large numbers".






            share|improve this answer


























            • There is no string in C

              – Zaffy
              Aug 20 '13 at 10:07






            • 1





              @Zaffy I know, that's why I wrote string(char), sorry for writing string as a code.

              – Don't You Worry Child
              Aug 20 '13 at 10:20











            • @Zaffy C11 7.1.1 1 "Definitions of terms. A string is a contiguous sequence of characters terminated by and including the first null character. ..."

              – chux
              Aug 20 '13 at 12:22






            • 1





              It is not generally true that an integer greater than what fits into 64 bits is not representable in some integer type in C. C 1999 and later provides for a variety of integer types, and an implementation may provide integer types of any size.

              – Eric Postpischil
              Aug 20 '13 at 13:09








            • 1





              @nishant: Clause 7.20 of the C standard describes the stdint.h headers, which describes types such as intmax_t and uintmax_t for integers of the greatest width in the implementation, along with types for specific widths, macros for writing constants of the various types, and other embellishments. The inttypes.h header in clause 7.8 provides format specifiers for using the types with printf.

              – Eric Postpischil
              Aug 20 '13 at 17:51
















            0












            0








            0







            If the number is greater than 64-bit, i.e. longer than what unsigned long long can hold, then no data type in C other than string(char) will be able to accomodate that value, store it as a string & try writing your own functions to operate (e.g. add, subtract, etc.) on these "very large numbers".






            share|improve this answer















            If the number is greater than 64-bit, i.e. longer than what unsigned long long can hold, then no data type in C other than string(char) will be able to accomodate that value, store it as a string & try writing your own functions to operate (e.g. add, subtract, etc.) on these "very large numbers".







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Aug 20 '13 at 10:21

























            answered Aug 20 '13 at 10:00









            Don't You Worry ChildDon't You Worry Child

            4,80111844




            4,80111844













            • There is no string in C

              – Zaffy
              Aug 20 '13 at 10:07






            • 1





              @Zaffy I know, that's why I wrote string(char), sorry for writing string as a code.

              – Don't You Worry Child
              Aug 20 '13 at 10:20











            • @Zaffy C11 7.1.1 1 "Definitions of terms. A string is a contiguous sequence of characters terminated by and including the first null character. ..."

              – chux
              Aug 20 '13 at 12:22






            • 1





              It is not generally true that an integer greater than what fits into 64 bits is not representable in some integer type in C. C 1999 and later provides for a variety of integer types, and an implementation may provide integer types of any size.

              – Eric Postpischil
              Aug 20 '13 at 13:09








            • 1





              @nishant: Clause 7.20 of the C standard describes the stdint.h headers, which describes types such as intmax_t and uintmax_t for integers of the greatest width in the implementation, along with types for specific widths, macros for writing constants of the various types, and other embellishments. The inttypes.h header in clause 7.8 provides format specifiers for using the types with printf.

              – Eric Postpischil
              Aug 20 '13 at 17:51





















            • There is no string in C

              – Zaffy
              Aug 20 '13 at 10:07






            • 1





              @Zaffy I know, that's why I wrote string(char), sorry for writing string as a code.

              – Don't You Worry Child
              Aug 20 '13 at 10:20











            • @Zaffy C11 7.1.1 1 "Definitions of terms. A string is a contiguous sequence of characters terminated by and including the first null character. ..."

              – chux
              Aug 20 '13 at 12:22






            • 1





              It is not generally true that an integer greater than what fits into 64 bits is not representable in some integer type in C. C 1999 and later provides for a variety of integer types, and an implementation may provide integer types of any size.

              – Eric Postpischil
              Aug 20 '13 at 13:09








            • 1





              @nishant: Clause 7.20 of the C standard describes the stdint.h headers, which describes types such as intmax_t and uintmax_t for integers of the greatest width in the implementation, along with types for specific widths, macros for writing constants of the various types, and other embellishments. The inttypes.h header in clause 7.8 provides format specifiers for using the types with printf.

              – Eric Postpischil
              Aug 20 '13 at 17:51



















            There is no string in C

            – Zaffy
            Aug 20 '13 at 10:07





            There is no string in C

            – Zaffy
            Aug 20 '13 at 10:07




            1




            1





            @Zaffy I know, that's why I wrote string(char), sorry for writing string as a code.

            – Don't You Worry Child
            Aug 20 '13 at 10:20





            @Zaffy I know, that's why I wrote string(char), sorry for writing string as a code.

            – Don't You Worry Child
            Aug 20 '13 at 10:20













            @Zaffy C11 7.1.1 1 "Definitions of terms. A string is a contiguous sequence of characters terminated by and including the first null character. ..."

            – chux
            Aug 20 '13 at 12:22





            @Zaffy C11 7.1.1 1 "Definitions of terms. A string is a contiguous sequence of characters terminated by and including the first null character. ..."

            – chux
            Aug 20 '13 at 12:22




            1




            1





            It is not generally true that an integer greater than what fits into 64 bits is not representable in some integer type in C. C 1999 and later provides for a variety of integer types, and an implementation may provide integer types of any size.

            – Eric Postpischil
            Aug 20 '13 at 13:09







            It is not generally true that an integer greater than what fits into 64 bits is not representable in some integer type in C. C 1999 and later provides for a variety of integer types, and an implementation may provide integer types of any size.

            – Eric Postpischil
            Aug 20 '13 at 13:09






            1




            1





            @nishant: Clause 7.20 of the C standard describes the stdint.h headers, which describes types such as intmax_t and uintmax_t for integers of the greatest width in the implementation, along with types for specific widths, macros for writing constants of the various types, and other embellishments. The inttypes.h header in clause 7.8 provides format specifiers for using the types with printf.

            – Eric Postpischil
            Aug 20 '13 at 17:51







            @nishant: Clause 7.20 of the C standard describes the stdint.h headers, which describes types such as intmax_t and uintmax_t for integers of the greatest width in the implementation, along with types for specific widths, macros for writing constants of the various types, and other embellishments. The inttypes.h header in clause 7.8 provides format specifiers for using the types with printf.

            – Eric Postpischil
            Aug 20 '13 at 17:51




















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f18331913%2fhow-to-read-and-assign-big-integers-in-c%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith