assigning to const int via pointer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The following code assigns a value to a `const int` via a
pointer.,

#include <stdio.h>

int 
main()
{
  const int x=5;
  int *ptr;
  ptr = &x;
  *ptr = 10;
  printf("%d",x);
}

The code gives `10` for the following compilation

    $gcc -o test test.c

It gives `5` when using optimisations switches.,

    $gcc -o test -O2 test.c

Feature or bug or any explanation for this? 

-- 
.O. A proud GNU user
..O http://www.joesteeve.tk/
OOO http://gnukid.5gigs.com/

Attachment: pgpfgDBWlBzDP.pgp
Description: PGP signature


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux