What is a null pointer assignment error?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jeyshree
    New Member
    • Jul 2010
    • 75

    What is a null pointer assignment error?

    hai,
    will someone please explain me what is null pointer assignment error.different persons say different reasons.some says the following code would generate null pointer assignment error.
    #include<stdio. h>
    #include<conio. h>
    main()
    {
    int *p=NULL;
    *p=10
    getch();
    }
    as we try to access the memory 0 it causes an error.
    but in my system i dont get this error.
    i am using turbo c++ compiler.(windo w7 os)
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    The pointer p contains an address of 0. That is an invalid location for all programs. Depending upon your compiler, you will get a null assignment error at compile time or no error at compile time but an "access: error at run time.

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      I don't believe the C Standard requires that you be informed of this error. It only guarantees that a program that dereferences a null pointer will not work properly.

      Comment

      • vivek nandan
        New Member
        • Jan 2011
        • 9

        #4
        you need to assign this pointer with address of some variable like ,
        int *i;
        int c=10;
        i=&c;
        //i=10 is an error as i is not a variable but a pointer to some memory!!

        Comment

        Working...