1 Replies - 212 Views - Last Post: 13 May 2013 - 07:00 PM Rate Topic: -----

#1 nothingme  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 66
  • Joined: 02-November 10

char *a=NULL; char& p = *a;

Posted 13 May 2013 - 05:55 PM

Hey guys I was wondering if anyone could explain this problem of this line

 
char *a=NULL; 
char& p = *a;


My understanding is that:

char *a=null //creates a null pointer.
char &p = *a //puts whatever is at the address of the pointer a into the the value at p (which is presumably initialised earlier?). But since a is null, this is gonna give a segmenation fault.

Is this correct?

Is This A Good Question/Topic? 0
  • +

Replies To: char *a=NULL; char& p = *a;

#2 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1072
  • View blog
  • Posts: 4,532
  • Joined: 09-June 09

Re: char *a=NULL; char& p = *a;

Posted 13 May 2013 - 07:00 PM

Yes, dereferencing a NULL pointer will cause a segmentation fault, since NULL is clearly outside the program's address space.

This post has been edited by jjl: 13 May 2013 - 07:00 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1