#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    1
    Rep Power
    0

    Crash program pointer


    Hello everybody
    I try these following codes
    It compiles without any error
    But in runtime the program will crash
    Thank you
    Code:
    #include<stdio.h>
    int main()
    {
           int i=1;
            int *j;
            j=&i;
     
    printf("%d\n",j);
    j=j+1;/*if it adds with ANY other numbers the program will NOT  crash like j=j+4 WHY?*/
    *j=i;
     
    printf("%d",*j);
    return 0;
     }
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    40
    Rep Power
    19
    Hacking trick could lead to crash your program or even damage some hardware. I know you know.
  4. #3
  5. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,392
    Rep Power
    1871
    Already comprehensively answered elsewhere
    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