Results: int *p=0; p++; printf("%d",*p); what should be output? 

Voters
0 You may not vote on this poll

  • 4
    0%
  • 2
    0%
  • garbage value
    0%
  • segmentation fault
    0%
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    1
    Rep Power
    0

    What will be output


    int *p = 0;
    p++;

    printf("%d",*p);

    what should be output and why?
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,363
    Rep Power
    1870
    > what should be output and why?
    should?

    That rather depends on the architecture of your machine (including the OS).

    For a modern machine with a protected memory OS, you ought to get a segfault.
    For all kinds of bare machines, any answer is plausible.

    IMO, if you're doing a quiz, the question is broken.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper

IMN logo majestic logo threadwatch logo seochat tools logo