Why does pointer to an address of a double variable not work in C? [duplicate] The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experiencec-behaviour of printf(“%d”, <double>)How to nicely format floating numbers to String without unnecessary decimal 0?How do function pointers in C work?Why does printf not flush after the call unless a newline is in the format string?Why is address zero used for the null pointer?printf by given pointer and format string. Issue with floatsHow do I achieve the theoretical maximum of 4 FLOPs per cycle?Why does Math.round(0.49999999999999994) return 1?Why does the C preprocessor interpret the word “linux” as the constant “1”?Memory addressing and pointersWhy can't I assign the address of a variable of one type(say double) to a pointer of int type?

Is this wall load bearing? Blueprints and photos attached

What are these Gizmos at Izaña Atmospheric Research Center in Spain?

How to split my screen on my Macbook Air?

Did God make two great lights or did He make the great light two?

How to delete random line from file using Unix command?

Didn't get enough time to take a Coding Test - what to do now?

Do working physicists consider Newtonian mechanics to be "falsified"?

How to politely respond to generic emails requesting a PhD/job in my lab? Without wasting too much time

Who or what is the being for whom Being is a question for Heidegger?

Why is Captain Marvel translated as male in Portugal?

Single author papers against my advisor's will?

Why is superheterodyning better than direct conversion?

How do you keep chess fun when your opponent constantly beats you?

Did the UK government pay "millions and millions of dollars" to try to snag Julian Assange?

I'm thinking of a number

Make it rain characters

Can a novice safely splice in wire to lengthen 5V charging cable?

I could not break this equation. Please help me

How are presidential pardons supposed to be used?

Is it ok to offer lower paid work as a trial period before negotiating for a full-time job?

Can smartphones with the same camera sensor have different image quality?

Wall plug outlet change

How should I replace vector<uint8_t>::const_iterator in an API?

Difference between "generating set" and free product?



Why does pointer to an address of a double variable not work in C? [duplicate]



The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experiencec-behaviour of printf(“%d”, <double>)How to nicely format floating numbers to String without unnecessary decimal 0?How do function pointers in C work?Why does printf not flush after the call unless a newline is in the format string?Why is address zero used for the null pointer?printf by given pointer and format string. Issue with floatsHow do I achieve the theoretical maximum of 4 FLOPs per cycle?Why does Math.round(0.49999999999999994) return 1?Why does the C preprocessor interpret the word “linux” as the constant “1”?Memory addressing and pointersWhy can't I assign the address of a variable of one type(say double) to a pointer of int type?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1
















This question is an exact duplicate of:



  • c-behaviour of printf(“%d”, <double>) [duplicate]

    1 answer



following the example : (working with x64 cpu and x64 GCC)



int a=7; printf("%d",*&a); //It prints 7
double a=7; printf("%d",*&a); //It prints an address


edited: thanks, i got it, i have to use %lf, but since 7 is stored within 1 byte , now i just want to access that byte. so, how to point to that lower byte of the double variable?










share|improve this question















marked as duplicate by Antti Haapala c
Users with the  c badge can single-handedly close c questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 22 at 7:01


This question was marked as an exact duplicate of an existing question.


















  • You don't assume that the result 7 is the address of a, do you? The expression *& takes an address and then dereferences it. Remove the * to actually get the address.

    – harper
    Mar 22 at 6:50







  • 1





    Use %lf to print double variable not %d. And then this *&a doesn't print address as both * and & nullify each other and it prints 7.000000.

    – Achal
    Mar 22 at 6:56











  • Removing the '*' will result in undefined behavior on x64 as typesize for a pointer exceeds storage for int.

    – David C. Rankin
    Mar 22 at 6:57











  • Your edit made the question worse. No, there is no "byte with 7"

    – Antti Haapala
    Mar 22 at 7:20






  • 2





    @bipulkalita I repeat. There is no byte with value 7, no matter how much you try to argue the case. So there is no way you're going to find a byte with value seven, period. Please google for IEEE 754

    – Antti Haapala
    Mar 22 at 7:24

















1
















This question is an exact duplicate of:



  • c-behaviour of printf(“%d”, <double>) [duplicate]

    1 answer



following the example : (working with x64 cpu and x64 GCC)



int a=7; printf("%d",*&a); //It prints 7
double a=7; printf("%d",*&a); //It prints an address


edited: thanks, i got it, i have to use %lf, but since 7 is stored within 1 byte , now i just want to access that byte. so, how to point to that lower byte of the double variable?










share|improve this question















marked as duplicate by Antti Haapala c
Users with the  c badge can single-handedly close c questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 22 at 7:01


This question was marked as an exact duplicate of an existing question.


















  • You don't assume that the result 7 is the address of a, do you? The expression *& takes an address and then dereferences it. Remove the * to actually get the address.

    – harper
    Mar 22 at 6:50







  • 1





    Use %lf to print double variable not %d. And then this *&a doesn't print address as both * and & nullify each other and it prints 7.000000.

    – Achal
    Mar 22 at 6:56











  • Removing the '*' will result in undefined behavior on x64 as typesize for a pointer exceeds storage for int.

    – David C. Rankin
    Mar 22 at 6:57











  • Your edit made the question worse. No, there is no "byte with 7"

    – Antti Haapala
    Mar 22 at 7:20






  • 2





    @bipulkalita I repeat. There is no byte with value 7, no matter how much you try to argue the case. So there is no way you're going to find a byte with value seven, period. Please google for IEEE 754

    – Antti Haapala
    Mar 22 at 7:24













1












1








1


1







This question is an exact duplicate of:



  • c-behaviour of printf(“%d”, <double>) [duplicate]

    1 answer



following the example : (working with x64 cpu and x64 GCC)



int a=7; printf("%d",*&a); //It prints 7
double a=7; printf("%d",*&a); //It prints an address


edited: thanks, i got it, i have to use %lf, but since 7 is stored within 1 byte , now i just want to access that byte. so, how to point to that lower byte of the double variable?










share|improve this question

















This question is an exact duplicate of:



  • c-behaviour of printf(“%d”, <double>) [duplicate]

    1 answer



following the example : (working with x64 cpu and x64 GCC)



int a=7; printf("%d",*&a); //It prints 7
double a=7; printf("%d",*&a); //It prints an address


edited: thanks, i got it, i have to use %lf, but since 7 is stored within 1 byte , now i just want to access that byte. so, how to point to that lower byte of the double variable?





This question is an exact duplicate of:



  • c-behaviour of printf(“%d”, <double>) [duplicate]

    1 answer







c printf double






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 7:10







bipul kalita

















asked Mar 22 at 6:48









bipul kalitabipul kalita

197




197




marked as duplicate by Antti Haapala c
Users with the  c badge can single-handedly close c questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 22 at 7:01


This question was marked as an exact duplicate of an existing question.









marked as duplicate by Antti Haapala c
Users with the  c badge can single-handedly close c questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 22 at 7:01


This question was marked as an exact duplicate of an existing question.














  • You don't assume that the result 7 is the address of a, do you? The expression *& takes an address and then dereferences it. Remove the * to actually get the address.

    – harper
    Mar 22 at 6:50







  • 1





    Use %lf to print double variable not %d. And then this *&a doesn't print address as both * and & nullify each other and it prints 7.000000.

    – Achal
    Mar 22 at 6:56











  • Removing the '*' will result in undefined behavior on x64 as typesize for a pointer exceeds storage for int.

    – David C. Rankin
    Mar 22 at 6:57











  • Your edit made the question worse. No, there is no "byte with 7"

    – Antti Haapala
    Mar 22 at 7:20






  • 2





    @bipulkalita I repeat. There is no byte with value 7, no matter how much you try to argue the case. So there is no way you're going to find a byte with value seven, period. Please google for IEEE 754

    – Antti Haapala
    Mar 22 at 7:24

















  • You don't assume that the result 7 is the address of a, do you? The expression *& takes an address and then dereferences it. Remove the * to actually get the address.

    – harper
    Mar 22 at 6:50







  • 1





    Use %lf to print double variable not %d. And then this *&a doesn't print address as both * and & nullify each other and it prints 7.000000.

    – Achal
    Mar 22 at 6:56











  • Removing the '*' will result in undefined behavior on x64 as typesize for a pointer exceeds storage for int.

    – David C. Rankin
    Mar 22 at 6:57











  • Your edit made the question worse. No, there is no "byte with 7"

    – Antti Haapala
    Mar 22 at 7:20






  • 2





    @bipulkalita I repeat. There is no byte with value 7, no matter how much you try to argue the case. So there is no way you're going to find a byte with value seven, period. Please google for IEEE 754

    – Antti Haapala
    Mar 22 at 7:24
















You don't assume that the result 7 is the address of a, do you? The expression *& takes an address and then dereferences it. Remove the * to actually get the address.

– harper
Mar 22 at 6:50






You don't assume that the result 7 is the address of a, do you? The expression *& takes an address and then dereferences it. Remove the * to actually get the address.

– harper
Mar 22 at 6:50





1




1





Use %lf to print double variable not %d. And then this *&a doesn't print address as both * and & nullify each other and it prints 7.000000.

– Achal
Mar 22 at 6:56





Use %lf to print double variable not %d. And then this *&a doesn't print address as both * and & nullify each other and it prints 7.000000.

– Achal
Mar 22 at 6:56













Removing the '*' will result in undefined behavior on x64 as typesize for a pointer exceeds storage for int.

– David C. Rankin
Mar 22 at 6:57





Removing the '*' will result in undefined behavior on x64 as typesize for a pointer exceeds storage for int.

– David C. Rankin
Mar 22 at 6:57













Your edit made the question worse. No, there is no "byte with 7"

– Antti Haapala
Mar 22 at 7:20





Your edit made the question worse. No, there is no "byte with 7"

– Antti Haapala
Mar 22 at 7:20




2




2





@bipulkalita I repeat. There is no byte with value 7, no matter how much you try to argue the case. So there is no way you're going to find a byte with value seven, period. Please google for IEEE 754

– Antti Haapala
Mar 22 at 7:24





@bipulkalita I repeat. There is no byte with value 7, no matter how much you try to argue the case. So there is no way you're going to find a byte with value seven, period. Please google for IEEE 754

– Antti Haapala
Mar 22 at 7:24












3 Answers
3






active

oldest

votes


















3














You don't print a double with %d format specifier. You must use %f.



Using wrong format specifier invokes undefined behaviour. The output (if you get one), cannot be justified in any way.






share|improve this answer






























    1














    Because you are printing double with "%d". Change it to "%lf"



    Regarding "//It prints an address"



    It is not printing address. Printf is taking address of double variable and dereferencing it as an integer. So whatever value it is printing is some junk number.






    share|improve this answer


















    • 2





      for printf, %lf is a myth. :)

      – Sourav Ghosh
      Mar 22 at 7:04











    • @SouravGhosh Just for my understanding: Then why/when "%lf" is required? How printf() differentiates float and double?

      – MayurK
      Mar 22 at 8:52







    • 1





      Actually @MayurK, A float when passed to a printf, will be promoted to double before printf receives it. hence it works with both %f and %lf.

      – Rai
      Mar 22 at 8:57


















    1















    "Why does pointer to an address of a double variable not work in C?"




    No. It works.



    double a=7; printf("%d",*&a); //It prints an address


    • It's just printing the data at the address specified by &a. The * is for dereferencing the address.

    And if you are saying that it's not working because it isn't printing the value of double a, it's simply because you are not using the right format specifier.




    • %d is the format specifier for int. If you want to print a double use %lf or %f.



      double a=7; printf("%lf",*&a); //This will print the double value







    share|improve this answer

























    • No. It works...that's an overstatement.

      – Sourav Ghosh
      Mar 22 at 7:04











    • Sorry @SouravGhosh, I didn't quite get you.

      – Rai
      Mar 22 at 8:52

















    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    You don't print a double with %d format specifier. You must use %f.



    Using wrong format specifier invokes undefined behaviour. The output (if you get one), cannot be justified in any way.






    share|improve this answer



























      3














      You don't print a double with %d format specifier. You must use %f.



      Using wrong format specifier invokes undefined behaviour. The output (if you get one), cannot be justified in any way.






      share|improve this answer

























        3












        3








        3







        You don't print a double with %d format specifier. You must use %f.



        Using wrong format specifier invokes undefined behaviour. The output (if you get one), cannot be justified in any way.






        share|improve this answer













        You don't print a double with %d format specifier. You must use %f.



        Using wrong format specifier invokes undefined behaviour. The output (if you get one), cannot be justified in any way.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 22 at 6:52









        Sourav GhoshSourav Ghosh

        111k15132191




        111k15132191























            1














            Because you are printing double with "%d". Change it to "%lf"



            Regarding "//It prints an address"



            It is not printing address. Printf is taking address of double variable and dereferencing it as an integer. So whatever value it is printing is some junk number.






            share|improve this answer


















            • 2





              for printf, %lf is a myth. :)

              – Sourav Ghosh
              Mar 22 at 7:04











            • @SouravGhosh Just for my understanding: Then why/when "%lf" is required? How printf() differentiates float and double?

              – MayurK
              Mar 22 at 8:52







            • 1





              Actually @MayurK, A float when passed to a printf, will be promoted to double before printf receives it. hence it works with both %f and %lf.

              – Rai
              Mar 22 at 8:57















            1














            Because you are printing double with "%d". Change it to "%lf"



            Regarding "//It prints an address"



            It is not printing address. Printf is taking address of double variable and dereferencing it as an integer. So whatever value it is printing is some junk number.






            share|improve this answer


















            • 2





              for printf, %lf is a myth. :)

              – Sourav Ghosh
              Mar 22 at 7:04











            • @SouravGhosh Just for my understanding: Then why/when "%lf" is required? How printf() differentiates float and double?

              – MayurK
              Mar 22 at 8:52







            • 1





              Actually @MayurK, A float when passed to a printf, will be promoted to double before printf receives it. hence it works with both %f and %lf.

              – Rai
              Mar 22 at 8:57













            1












            1








            1







            Because you are printing double with "%d". Change it to "%lf"



            Regarding "//It prints an address"



            It is not printing address. Printf is taking address of double variable and dereferencing it as an integer. So whatever value it is printing is some junk number.






            share|improve this answer













            Because you are printing double with "%d". Change it to "%lf"



            Regarding "//It prints an address"



            It is not printing address. Printf is taking address of double variable and dereferencing it as an integer. So whatever value it is printing is some junk number.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 22 at 6:57









            MayurKMayurK

            1,441619




            1,441619







            • 2





              for printf, %lf is a myth. :)

              – Sourav Ghosh
              Mar 22 at 7:04











            • @SouravGhosh Just for my understanding: Then why/when "%lf" is required? How printf() differentiates float and double?

              – MayurK
              Mar 22 at 8:52







            • 1





              Actually @MayurK, A float when passed to a printf, will be promoted to double before printf receives it. hence it works with both %f and %lf.

              – Rai
              Mar 22 at 8:57












            • 2





              for printf, %lf is a myth. :)

              – Sourav Ghosh
              Mar 22 at 7:04











            • @SouravGhosh Just for my understanding: Then why/when "%lf" is required? How printf() differentiates float and double?

              – MayurK
              Mar 22 at 8:52







            • 1





              Actually @MayurK, A float when passed to a printf, will be promoted to double before printf receives it. hence it works with both %f and %lf.

              – Rai
              Mar 22 at 8:57







            2




            2





            for printf, %lf is a myth. :)

            – Sourav Ghosh
            Mar 22 at 7:04





            for printf, %lf is a myth. :)

            – Sourav Ghosh
            Mar 22 at 7:04













            @SouravGhosh Just for my understanding: Then why/when "%lf" is required? How printf() differentiates float and double?

            – MayurK
            Mar 22 at 8:52






            @SouravGhosh Just for my understanding: Then why/when "%lf" is required? How printf() differentiates float and double?

            – MayurK
            Mar 22 at 8:52





            1




            1





            Actually @MayurK, A float when passed to a printf, will be promoted to double before printf receives it. hence it works with both %f and %lf.

            – Rai
            Mar 22 at 8:57





            Actually @MayurK, A float when passed to a printf, will be promoted to double before printf receives it. hence it works with both %f and %lf.

            – Rai
            Mar 22 at 8:57











            1















            "Why does pointer to an address of a double variable not work in C?"




            No. It works.



            double a=7; printf("%d",*&a); //It prints an address


            • It's just printing the data at the address specified by &a. The * is for dereferencing the address.

            And if you are saying that it's not working because it isn't printing the value of double a, it's simply because you are not using the right format specifier.




            • %d is the format specifier for int. If you want to print a double use %lf or %f.



              double a=7; printf("%lf",*&a); //This will print the double value







            share|improve this answer

























            • No. It works...that's an overstatement.

              – Sourav Ghosh
              Mar 22 at 7:04











            • Sorry @SouravGhosh, I didn't quite get you.

              – Rai
              Mar 22 at 8:52















            1















            "Why does pointer to an address of a double variable not work in C?"




            No. It works.



            double a=7; printf("%d",*&a); //It prints an address


            • It's just printing the data at the address specified by &a. The * is for dereferencing the address.

            And if you are saying that it's not working because it isn't printing the value of double a, it's simply because you are not using the right format specifier.




            • %d is the format specifier for int. If you want to print a double use %lf or %f.



              double a=7; printf("%lf",*&a); //This will print the double value







            share|improve this answer

























            • No. It works...that's an overstatement.

              – Sourav Ghosh
              Mar 22 at 7:04











            • Sorry @SouravGhosh, I didn't quite get you.

              – Rai
              Mar 22 at 8:52













            1












            1








            1








            "Why does pointer to an address of a double variable not work in C?"




            No. It works.



            double a=7; printf("%d",*&a); //It prints an address


            • It's just printing the data at the address specified by &a. The * is for dereferencing the address.

            And if you are saying that it's not working because it isn't printing the value of double a, it's simply because you are not using the right format specifier.




            • %d is the format specifier for int. If you want to print a double use %lf or %f.



              double a=7; printf("%lf",*&a); //This will print the double value







            share|improve this answer
















            "Why does pointer to an address of a double variable not work in C?"




            No. It works.



            double a=7; printf("%d",*&a); //It prints an address


            • It's just printing the data at the address specified by &a. The * is for dereferencing the address.

            And if you are saying that it's not working because it isn't printing the value of double a, it's simply because you are not using the right format specifier.




            • %d is the format specifier for int. If you want to print a double use %lf or %f.



              double a=7; printf("%lf",*&a); //This will print the double value








            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 22 at 8:51

























            answered Mar 22 at 6:59









            RaiRai

            1,1424823




            1,1424823












            • No. It works...that's an overstatement.

              – Sourav Ghosh
              Mar 22 at 7:04











            • Sorry @SouravGhosh, I didn't quite get you.

              – Rai
              Mar 22 at 8:52

















            • No. It works...that's an overstatement.

              – Sourav Ghosh
              Mar 22 at 7:04











            • Sorry @SouravGhosh, I didn't quite get you.

              – Rai
              Mar 22 at 8:52
















            No. It works...that's an overstatement.

            – Sourav Ghosh
            Mar 22 at 7:04





            No. It works...that's an overstatement.

            – Sourav Ghosh
            Mar 22 at 7:04













            Sorry @SouravGhosh, I didn't quite get you.

            – Rai
            Mar 22 at 8:52





            Sorry @SouravGhosh, I didn't quite get you.

            – Rai
            Mar 22 at 8:52



            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현