question about printf

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Hiral
    New Member
    • Apr 2007
    • 1

    question about printf

    what is the output of

    void main()
    {
    printf("%d");
    }
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    #2
    The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

    Please read the Posting Guidelines and particularly the Coursework Posting Guidlines.

    Then when you are ready post a new question in this thread.

    MODERATOR

    Comment

    • RedSon
      Recognized Expert Expert
      • Jan 2007
      • 4980

      #3
      Using a good, clear thread title is important. The reasons for this are:
      • We want this site to grow, many of our new members find the site using a search engine, by using a good thread title you will help us grow the site by helping us get better search engine rankings.
      • Using a good title will benefit you too because other members of the forum will be less likely to skip over your thread and it allows the experts to quickly scan through the forum for questions they know the answer to.
      • If the threads are well titled it allows other users to easily see if there have been any threads that could be relevant to their own current problem.
      • It is in everybody's best interests to post properly titled threads as the more time the moderators have to spend on managing titles the less time they have available to give answers to the questions posed.

      Comment

      • Savage
        Recognized Expert Top Contributor
        • Feb 2007
        • 1759

        #4
        The output will be ZERO


        Savage

        Comment

        • nmadct
          Recognized Expert New Member
          • Jan 2007
          • 83

          #5
          Originally posted by Hiral
          what is the output of

          Code:
          void main()
          {
              printf("%d");
          }
          Try it and find out!

          Comment

          • sicarie
            Recognized Expert Specialist
            • Nov 2006
            • 4677

            #6
            Originally posted by Savage
            The output will be ZERO


            Savage
            Umm, I'm pretty sure that's incorrect. Did you try running it?

            Comment

            • Savage
              Recognized Expert Top Contributor
              • Feb 2007
              • 1759

              #7
              Originally posted by sicarie
              Umm, I'm pretty sure that's incorrect. Did you try running it?
              Yes,I runed it and it gaved me a 0.

              Savage

              Comment

              • Banfa
                Recognized Expert Expert
                • Feb 2006
                • 9067

                #8
                The output could be anything, it invokes undefined behaviour on at least 2 counts.

                Comment

                • Ganon11
                  Recognized Expert Specialist
                  • Oct 2006
                  • 3651

                  #9
                  Originally posted by Banfa
                  The output could be anything, it invokes undefined behaviour on at least 2 counts.
                  Let me guess:

                  1) void main() instead of int main()
                  2) printf("%d"); is supposed to print an integer value, but no such value is specified.

                  Comment

                  • chella
                    New Member
                    • Mar 2007
                    • 51

                    #10
                    Hi,
                    The value of the statement printf("%d") varies depending on the compiler we use.
                    In Unix, cc compiler will produce a result as some unknown integer value.
                    In Turbo C compiler the result will be zero.

                    This depends on the compiler which we use


                    Regrads,
                    Chella

                    Comment

                    • JosAH
                      Recognized Expert MVP
                      • Mar 2007
                      • 11453

                      #11
                      Originally posted by chella
                      Hi,
                      The value of the statement printf("%d") varies depending on the compiler we use.
                      In Unix, cc compiler will produce a result as some unknown integer value.
                      In Turbo C compiler the result will be zero.

                      This depends on the compiler which we use


                      Regrads,
                      Chella
                      My compiler makes daemons fly out of your nose. As said before: calling the
                      printf function like this causes undefined behaviour. Every (educated?) guess
                      what the output would/could be is just guessing. Nothing can be said about it.

                      kind regards,

                      Jos

                      Comment

                      • Banfa
                        Recognized Expert Expert
                        • Feb 2006
                        • 9067

                        #12
                        Originally posted by Ganon11
                        1) void main() instead of int main()
                        2) printf("%d"); is supposed to print an integer value, but no such value is specified.
                        That is what I was thinking of :D

                        Comment

                        Working...