Thread: pointer question

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    4

    pointer question

    I cannot find the answer to this question anywhere, if anyone can help it would be greatly appreciated:

    What is the effect of dereferencing a pointer variable, which has the value NULL?

  2. #2
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    a seg fault

  3. #3
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    You program would simply crash

    By C standards (correct me if wrong)
    #define NULL ((void*)0)

    By C++ standards
    #define NULL 0

    There's no place in your main memory with adress 0 so that's what would happen.

    EDIT: a segmentation fault is when a process tries to acess memory that doesn't belong to it. Should acessing memory that doesn't exist be called the same way??
    Last edited by xErath; 11-17-2004 at 07:22 PM.

  4. #4
    Registered User
    Join Date
    Nov 2004
    Posts
    4
    Thanks to both of you

  5. #5
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Quote Originally Posted by xErath
    EDIT: a segmentation fault is when a process tries to acess memory that doesn't belong to it. Should acessing memory that doesn't exist be called the same way??
    Incorrect. From 'man 7 signal':
    Code:
    SIGSEGV      11       Core    Invalid memory reference
    It's not limited to memory that's not owned by you. Any invalid memory reference causes a segmentation fault.
    If you understand what you're doing, you're not learning anything.

  6. #6
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    Ah, thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. Easy pointer question
    By Edo in forum C++ Programming
    Replies: 3
    Last Post: 01-19-2009, 10:54 AM
  3. char pointer to pointer question
    By Salt Shaker in forum C Programming
    Replies: 3
    Last Post: 01-10-2009, 11:59 AM
  4. Pointer question
    By rakan in forum C++ Programming
    Replies: 2
    Last Post: 11-19-2006, 02:23 AM
  5. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM