Output of code snippet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • himanigarg
    New Member
    • Oct 2007
    • 7

    Output of code snippet

    what is the output of the following code:
    [code=c]
    main()
    {
    char p[]="%d\n";
    p[1]='c';
    printf(p,65);
    }
    [/code]
    i need the explanation of the output.
    Last edited by sicarie; Oct 18 '07, 04:05 PM. Reason: Read the Guidelines, use code tags.
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    And just out of curiosity, why can't you put this in a compiler and run it?

    Comment

    • jwwicks
      New Member
      • Oct 2007
      • 19

      #3
      Hello,

      Originally posted by himanigarg
      what is the output of the following code:
      [code=c]
      main()
      {
      char p[]="%d\n";
      p[1]='c';
      printf(p,65);
      }
      [/code]
      i need the explanation of the output.
      Hint: The format specifier gets modified from d to c. So what ASCII character is 65 decimal.

      John

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #4
        Originally posted by jwwicks
        Hello,



        Hint: The format specifier gets modified from d to c. So what ASCII character is 65 decimal.

        John
        That would be a good hint if there weren't 4 or 5 things wrong with this code. This will error out and not compile.

        Comment

        Working...