%p Format specifier in c











up vote
13
down vote

favorite
2












How are the specifiers %p and %Fp working in the following code?



void main() 
{
int i=85;

printf("%p %Fp",i,i);

getch();
}


I am getting the o/p as 0000000000000055 0000000000000055










share|improve this question
























  • working as it should be, pointer and float, what's the problem?
    – halfelf
    Sep 28 '12 at 3:14















up vote
13
down vote

favorite
2












How are the specifiers %p and %Fp working in the following code?



void main() 
{
int i=85;

printf("%p %Fp",i,i);

getch();
}


I am getting the o/p as 0000000000000055 0000000000000055










share|improve this question
























  • working as it should be, pointer and float, what's the problem?
    – halfelf
    Sep 28 '12 at 3:14













up vote
13
down vote

favorite
2









up vote
13
down vote

favorite
2






2





How are the specifiers %p and %Fp working in the following code?



void main() 
{
int i=85;

printf("%p %Fp",i,i);

getch();
}


I am getting the o/p as 0000000000000055 0000000000000055










share|improve this question















How are the specifiers %p and %Fp working in the following code?



void main() 
{
int i=85;

printf("%p %Fp",i,i);

getch();
}


I am getting the o/p as 0000000000000055 0000000000000055







c format-specifiers






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 28 '12 at 3:14









jonsca

8,598114757




8,598114757










asked Sep 28 '12 at 3:05









poorvankBhatia

4,000104890




4,000104890












  • working as it should be, pointer and float, what's the problem?
    – halfelf
    Sep 28 '12 at 3:14


















  • working as it should be, pointer and float, what's the problem?
    – halfelf
    Sep 28 '12 at 3:14
















working as it should be, pointer and float, what's the problem?
– halfelf
Sep 28 '12 at 3:14




working as it should be, pointer and float, what's the problem?
– halfelf
Sep 28 '12 at 3:14












5 Answers
5






active

oldest

votes

















up vote
18
down vote



accepted










If this is what you are asking, %p and %Fp print out a pointer, specifically the address to which the pointer refers, and since it is printing out a part of your computer's architecture, it does so in Hexadecimal.



In C, you can cast between a pointer and an int, since a pointer is just a 32-bit or 64-bit number (depending on machine architecture) referring to the aforementioned chunk of memory.



And of course, 55 in hex is 85 in decimal.






share|improve this answer

















  • 1




    %Fp is not for pointer, depending on compilers. For gcc/clang, %F is for float, similar to %f with a little diff. The following p will be treated as a normal char to print.
    – halfelf
    Sep 28 '12 at 3:23










  • hmm, so why is he getting 000.... 55 twice and no p? (i agree with you, as i just ran it myself)
    – David Christo
    Sep 28 '12 at 3:28


















up vote
2
down vote













%p is for printing a pointer address.



85 in decimal is 55 in hexadecimal.



On your system pointers are 64bit, so the full hexidecimal representation is: 0000000000000055






share|improve this answer




























    up vote
    2
    down vote













    Here is the compilation output from my machine:



    format.c:7:5: warning: format ‘%p’ expects argument of type ‘void *’, but argument 2 has type ‘int’ [-Wformat]



    format.c:7:5: warning: format ‘%F’ expects argument of type ‘double’, but argument 3 has type ‘int’ [-Wformat]



    so there are warnings but it does compile and the output is:
    0x55 0.000000p



    I am surprised you aren't getting a p at the end. Are you sure code and output matches? I guess it isn't impossible for the address of i to also be 0x0...055..but something looks wrong here.



    btw: the typical usage of %p would be to print an address i.e. &i as opposed an int






    share|improve this answer




























      up vote
      2
      down vote













      It's purpose is to print a pointer value in an implementation defined format. The corresponding argument must be a void * value.



      And %p is used to printing the address of a pointer the addresses are depending by our system bit.






      share|improve this answer






























        up vote
        1
        down vote













        Addition to what @Myforwik said



        %p is for printing a pointer address.



        %Fp is probably used to format a FAR pointer which is of the form --> (0x1234:0x5678)



        and 85 in decimal is 55 in hexadecimal.



        I hope its okay now.



        References :
        http://www.lix.polytechnique.fr/~liberti/public/computing/prog/c/C/FUNCTIONS/format.html
        http://www.winehq.org/pipermail/wine-devel/2005-March/034390.html






        share|improve this answer





















          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',
          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%2f12633067%2fp-format-specifier-in-c%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          5 Answers
          5






          active

          oldest

          votes








          5 Answers
          5






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          18
          down vote



          accepted










          If this is what you are asking, %p and %Fp print out a pointer, specifically the address to which the pointer refers, and since it is printing out a part of your computer's architecture, it does so in Hexadecimal.



          In C, you can cast between a pointer and an int, since a pointer is just a 32-bit or 64-bit number (depending on machine architecture) referring to the aforementioned chunk of memory.



          And of course, 55 in hex is 85 in decimal.






          share|improve this answer

















          • 1




            %Fp is not for pointer, depending on compilers. For gcc/clang, %F is for float, similar to %f with a little diff. The following p will be treated as a normal char to print.
            – halfelf
            Sep 28 '12 at 3:23










          • hmm, so why is he getting 000.... 55 twice and no p? (i agree with you, as i just ran it myself)
            – David Christo
            Sep 28 '12 at 3:28















          up vote
          18
          down vote



          accepted










          If this is what you are asking, %p and %Fp print out a pointer, specifically the address to which the pointer refers, and since it is printing out a part of your computer's architecture, it does so in Hexadecimal.



          In C, you can cast between a pointer and an int, since a pointer is just a 32-bit or 64-bit number (depending on machine architecture) referring to the aforementioned chunk of memory.



          And of course, 55 in hex is 85 in decimal.






          share|improve this answer

















          • 1




            %Fp is not for pointer, depending on compilers. For gcc/clang, %F is for float, similar to %f with a little diff. The following p will be treated as a normal char to print.
            – halfelf
            Sep 28 '12 at 3:23










          • hmm, so why is he getting 000.... 55 twice and no p? (i agree with you, as i just ran it myself)
            – David Christo
            Sep 28 '12 at 3:28













          up vote
          18
          down vote



          accepted







          up vote
          18
          down vote



          accepted






          If this is what you are asking, %p and %Fp print out a pointer, specifically the address to which the pointer refers, and since it is printing out a part of your computer's architecture, it does so in Hexadecimal.



          In C, you can cast between a pointer and an int, since a pointer is just a 32-bit or 64-bit number (depending on machine architecture) referring to the aforementioned chunk of memory.



          And of course, 55 in hex is 85 in decimal.






          share|improve this answer












          If this is what you are asking, %p and %Fp print out a pointer, specifically the address to which the pointer refers, and since it is printing out a part of your computer's architecture, it does so in Hexadecimal.



          In C, you can cast between a pointer and an int, since a pointer is just a 32-bit or 64-bit number (depending on machine architecture) referring to the aforementioned chunk of memory.



          And of course, 55 in hex is 85 in decimal.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Sep 28 '12 at 3:17









          David Christo

          691311




          691311








          • 1




            %Fp is not for pointer, depending on compilers. For gcc/clang, %F is for float, similar to %f with a little diff. The following p will be treated as a normal char to print.
            – halfelf
            Sep 28 '12 at 3:23










          • hmm, so why is he getting 000.... 55 twice and no p? (i agree with you, as i just ran it myself)
            – David Christo
            Sep 28 '12 at 3:28














          • 1




            %Fp is not for pointer, depending on compilers. For gcc/clang, %F is for float, similar to %f with a little diff. The following p will be treated as a normal char to print.
            – halfelf
            Sep 28 '12 at 3:23










          • hmm, so why is he getting 000.... 55 twice and no p? (i agree with you, as i just ran it myself)
            – David Christo
            Sep 28 '12 at 3:28








          1




          1




          %Fp is not for pointer, depending on compilers. For gcc/clang, %F is for float, similar to %f with a little diff. The following p will be treated as a normal char to print.
          – halfelf
          Sep 28 '12 at 3:23




          %Fp is not for pointer, depending on compilers. For gcc/clang, %F is for float, similar to %f with a little diff. The following p will be treated as a normal char to print.
          – halfelf
          Sep 28 '12 at 3:23












          hmm, so why is he getting 000.... 55 twice and no p? (i agree with you, as i just ran it myself)
          – David Christo
          Sep 28 '12 at 3:28




          hmm, so why is he getting 000.... 55 twice and no p? (i agree with you, as i just ran it myself)
          – David Christo
          Sep 28 '12 at 3:28












          up vote
          2
          down vote













          %p is for printing a pointer address.



          85 in decimal is 55 in hexadecimal.



          On your system pointers are 64bit, so the full hexidecimal representation is: 0000000000000055






          share|improve this answer

























            up vote
            2
            down vote













            %p is for printing a pointer address.



            85 in decimal is 55 in hexadecimal.



            On your system pointers are 64bit, so the full hexidecimal representation is: 0000000000000055






            share|improve this answer























              up vote
              2
              down vote










              up vote
              2
              down vote









              %p is for printing a pointer address.



              85 in decimal is 55 in hexadecimal.



              On your system pointers are 64bit, so the full hexidecimal representation is: 0000000000000055






              share|improve this answer












              %p is for printing a pointer address.



              85 in decimal is 55 in hexadecimal.



              On your system pointers are 64bit, so the full hexidecimal representation is: 0000000000000055







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Sep 28 '12 at 3:14









              Myforwik

              1,86142537




              1,86142537






















                  up vote
                  2
                  down vote













                  Here is the compilation output from my machine:



                  format.c:7:5: warning: format ‘%p’ expects argument of type ‘void *’, but argument 2 has type ‘int’ [-Wformat]



                  format.c:7:5: warning: format ‘%F’ expects argument of type ‘double’, but argument 3 has type ‘int’ [-Wformat]



                  so there are warnings but it does compile and the output is:
                  0x55 0.000000p



                  I am surprised you aren't getting a p at the end. Are you sure code and output matches? I guess it isn't impossible for the address of i to also be 0x0...055..but something looks wrong here.



                  btw: the typical usage of %p would be to print an address i.e. &i as opposed an int






                  share|improve this answer

























                    up vote
                    2
                    down vote













                    Here is the compilation output from my machine:



                    format.c:7:5: warning: format ‘%p’ expects argument of type ‘void *’, but argument 2 has type ‘int’ [-Wformat]



                    format.c:7:5: warning: format ‘%F’ expects argument of type ‘double’, but argument 3 has type ‘int’ [-Wformat]



                    so there are warnings but it does compile and the output is:
                    0x55 0.000000p



                    I am surprised you aren't getting a p at the end. Are you sure code and output matches? I guess it isn't impossible for the address of i to also be 0x0...055..but something looks wrong here.



                    btw: the typical usage of %p would be to print an address i.e. &i as opposed an int






                    share|improve this answer























                      up vote
                      2
                      down vote










                      up vote
                      2
                      down vote









                      Here is the compilation output from my machine:



                      format.c:7:5: warning: format ‘%p’ expects argument of type ‘void *’, but argument 2 has type ‘int’ [-Wformat]



                      format.c:7:5: warning: format ‘%F’ expects argument of type ‘double’, but argument 3 has type ‘int’ [-Wformat]



                      so there are warnings but it does compile and the output is:
                      0x55 0.000000p



                      I am surprised you aren't getting a p at the end. Are you sure code and output matches? I guess it isn't impossible for the address of i to also be 0x0...055..but something looks wrong here.



                      btw: the typical usage of %p would be to print an address i.e. &i as opposed an int






                      share|improve this answer












                      Here is the compilation output from my machine:



                      format.c:7:5: warning: format ‘%p’ expects argument of type ‘void *’, but argument 2 has type ‘int’ [-Wformat]



                      format.c:7:5: warning: format ‘%F’ expects argument of type ‘double’, but argument 3 has type ‘int’ [-Wformat]



                      so there are warnings but it does compile and the output is:
                      0x55 0.000000p



                      I am surprised you aren't getting a p at the end. Are you sure code and output matches? I guess it isn't impossible for the address of i to also be 0x0...055..but something looks wrong here.



                      btw: the typical usage of %p would be to print an address i.e. &i as opposed an int







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Sep 28 '12 at 4:19









                      user657862

                      261210




                      261210






















                          up vote
                          2
                          down vote













                          It's purpose is to print a pointer value in an implementation defined format. The corresponding argument must be a void * value.



                          And %p is used to printing the address of a pointer the addresses are depending by our system bit.






                          share|improve this answer



























                            up vote
                            2
                            down vote













                            It's purpose is to print a pointer value in an implementation defined format. The corresponding argument must be a void * value.



                            And %p is used to printing the address of a pointer the addresses are depending by our system bit.






                            share|improve this answer

























                              up vote
                              2
                              down vote










                              up vote
                              2
                              down vote









                              It's purpose is to print a pointer value in an implementation defined format. The corresponding argument must be a void * value.



                              And %p is used to printing the address of a pointer the addresses are depending by our system bit.






                              share|improve this answer














                              It's purpose is to print a pointer value in an implementation defined format. The corresponding argument must be a void * value.



                              And %p is used to printing the address of a pointer the addresses are depending by our system bit.







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Sep 28 '12 at 8:04







                              user647772

















                              answered Sep 28 '12 at 5:18









                              reegan vijay

                              13410




                              13410






















                                  up vote
                                  1
                                  down vote













                                  Addition to what @Myforwik said



                                  %p is for printing a pointer address.



                                  %Fp is probably used to format a FAR pointer which is of the form --> (0x1234:0x5678)



                                  and 85 in decimal is 55 in hexadecimal.



                                  I hope its okay now.



                                  References :
                                  http://www.lix.polytechnique.fr/~liberti/public/computing/prog/c/C/FUNCTIONS/format.html
                                  http://www.winehq.org/pipermail/wine-devel/2005-March/034390.html






                                  share|improve this answer

























                                    up vote
                                    1
                                    down vote













                                    Addition to what @Myforwik said



                                    %p is for printing a pointer address.



                                    %Fp is probably used to format a FAR pointer which is of the form --> (0x1234:0x5678)



                                    and 85 in decimal is 55 in hexadecimal.



                                    I hope its okay now.



                                    References :
                                    http://www.lix.polytechnique.fr/~liberti/public/computing/prog/c/C/FUNCTIONS/format.html
                                    http://www.winehq.org/pipermail/wine-devel/2005-March/034390.html






                                    share|improve this answer























                                      up vote
                                      1
                                      down vote










                                      up vote
                                      1
                                      down vote









                                      Addition to what @Myforwik said



                                      %p is for printing a pointer address.



                                      %Fp is probably used to format a FAR pointer which is of the form --> (0x1234:0x5678)



                                      and 85 in decimal is 55 in hexadecimal.



                                      I hope its okay now.



                                      References :
                                      http://www.lix.polytechnique.fr/~liberti/public/computing/prog/c/C/FUNCTIONS/format.html
                                      http://www.winehq.org/pipermail/wine-devel/2005-March/034390.html






                                      share|improve this answer












                                      Addition to what @Myforwik said



                                      %p is for printing a pointer address.



                                      %Fp is probably used to format a FAR pointer which is of the form --> (0x1234:0x5678)



                                      and 85 in decimal is 55 in hexadecimal.



                                      I hope its okay now.



                                      References :
                                      http://www.lix.polytechnique.fr/~liberti/public/computing/prog/c/C/FUNCTIONS/format.html
                                      http://www.winehq.org/pipermail/wine-devel/2005-March/034390.html







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Aug 1 '13 at 15:06









                                      Saurabh Rana

                                      1,60611218




                                      1,60611218






























                                          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.





                                          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                          Please pay close attention to the following guidance:


                                          • 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%2f12633067%2fp-format-specifier-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







                                          這個網誌中的熱門文章

                                          Xamarin.form Move up view when keyboard appear

                                          Post-Redirect-Get with Spring WebFlux and Thymeleaf

                                          Anylogic : not able to use stopDelay()