EmbLogic's Blog

E-14 Pointers

declared char *ptr;
printed the address allocated to ptr (&ptr), garbage address of ptr (ptr ) and the garbage value (*ptr)
Error: Segmentation Fault.
Can you please explain why?

5 Responses to E-14 Pointers

  1. manoj says:

    show the code..

    sometimes it depends on, how you are printing..

    • ayush.gupta says:

      char *ptr;
      printf(“Address allocated to ptr is %p\n ptr pointing to garbage address %p\n which holds the garbage value %c\n”,&ptr,ptr,*ptr);

      gives segmentation fault (core dumped).
      It should at least print the address and garbage value… still facing error.

  2. manoj says:

    Well,

    On my system it is running very well.. although it should be a segmentation fault in the last print i.e. *ptr… but it is giving some output. But first two are absolutely correct.. no segmentation fault is there..

  3. maybe the *ptr in ur case is pointing to some address outside its own memory segment.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>