c program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ravijv12
    New Member
    • Oct 2008
    • 5

    c program

    i had doubt regrdng this progrm... pls explain..

    #include<stdio. h>
    void main()
    {
    int a, b;
    printf("enter d value fof a and b");
    scanf("%d%d", &a, &b);
    printf("%d%d",& b,b);
    }

    wats d op of this program... pls get soon..
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    You wrote 'void main()' which results in undefined behaviour.

    kind regards,

    Jos

    Comment

    • newb16
      Contributor
      • Jul 2008
      • 687

      #3
      Originally posted by JosAH
      You wrote 'void main()' which results in undefined behaviour.
      Also he forgot code tags, that is by an order of magnitude larger sin.
      And let alone printf("%d%d",& b,b) where &b is printing b's address ( if pointer and int are both 32 bit).

      Comment

      • donbock
        Recognized Expert Top Contributor
        • Mar 2008
        • 2427

        #4
        Originally posted by ravijv12
        Code:
        printf("%d%d",&b,b);
        }
        This format string is incompatible with the arguments: %d is for printing an int; &b is a pointer, b is an int.
        Why would you want to print two numbers without any space between them?

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by newb16
          Also he forgot code tags, that is by an order of magnitude larger sin.
          And let alone printf("%d%d",& b,b) where &b is printing b's address ( if pointer and int are both 32 bit).
          The OP also didn't write his/her post in English; as a non-native speaker I had to
          guess for the meaning of 'wats d op of this program... pls get soon..'.

          My crappy-post-o-meter is rising ;-)

          kind regards,

          Jos

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            I have deleted the OP's other identical thread.

            kind regards,

            Jos

            Comment

            • ravijv12
              New Member
              • Oct 2008
              • 5

              #7
              Originally posted by JosAH
              You wrote 'void main()' which results in undefined behaviour.

              kind regards,

              Jos

              sir ,
              actually i want to print memory adress of b & value of b

              Comment

              • ravijv12
                New Member
                • Oct 2008
                • 5

                #8
                Originally posted by donbock
                This format string is incompatible with the arguments: %d is for printing an int; &b is a pointer, b is an int.
                Why would you want to print two numbers without any space between them?

                actually i wanted print both address and value of b ,

                Comment

                • Laharl
                  Recognized Expert Contributor
                  • Sep 2007
                  • 849

                  #9
                  If you want to see what it outputs, I recommend compiling and running this code. For the code itself, I recommend printing the address in hexadecimal and add some whitespace in between the two numbers so you can tell them apart.

                  Comment

                  • donbock
                    Recognized Expert Top Contributor
                    • Mar 2008
                    • 2427

                    #10
                    Originally posted by ravijv12
                    actually i wanted print both address and value of b ,
                    "%p" is preferred for printing the address of a variable.

                    Comment

                    Working...