Printf during Crash

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • arunraj2002in
    New Member
    • Jun 2007
    • 22

    Printf during Crash

    Consider;

    void crash(void)
    {
    printf("hello") ;
    *((*char)0) = 0;
    }

    The above program leads to crash. Why?

    Also string "hello" won't get printed. Why?
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by arunraj2002in
    Consider;

    void crash(void)
    {
    printf("hello") ;
    *((*char)0) = 0;
    }

    The above program leads to crash. Why?

    Also string "hello" won't get printed. Why?
    Shouldn't that be *((char*)0)=0;? I think your version doesn't even compile.

    kind regards,

    Jos

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      You don't own memory location 0. Program crashes with access violation for using memory outside the process address space.

      Hello printed. However, the output may still be in the output buffer when the crash occurs.

      Comment

      Working...