Thread: Why does it behave so

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    2

    Why does it behave so

    HI,

    Plz let me know, why this program behave so.

    Rgds,
    madhu

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    It behaves like it does because its doing what you told it to do.

    What exactly is it supposed to do?
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Registered User
    Join Date
    Dec 2003
    Posts
    2

    I want the reason..

    Hi,

    Yes i know.
    But i would like to know the reason for that.
    how it is being interpreted.
    If you know plz post the answer

    Regards,
    madhu

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Heh, let's give the newbies an ioccc entry and see what they make of it.
    If your teacher gave you this, they're an idiot.
    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.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    The hardest part of it is to understand that
    i[p] and p[i] are the same (p is a pointer, i is an integer).
    And a string literal is a pointer, so
    i["bla"]
    means the same as
    "bla"[i]
    or
    const char *p = "bla";
    p[i]
    so it takes the ith character (0-based).

    But I fully agree with Salem.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Registered User
    Join Date
    Dec 2001
    Posts
    44
    Even worse is the fact that the output is implimentation dependent, and that the putchar line invokes undefined behaviour!

    I'm glad I didn't learn C from someone who hands out such code.

    Ian Woods

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > and that the putchar line invokes undefined behaviour!
    LOL, so that's why it only works for me first thing in the morning.

    > putchar ( ++c=='Z' ? c = c/ 9:33^b&1);
    After 9:33 am, it all goes weird on me
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SetTimer() doesn't behave.
    By OnionKnight in forum Windows Programming
    Replies: 9
    Last Post: 04-09-2007, 03:52 PM
  2. Is typeid is still in use ?
    By dude543 in forum C++ Programming
    Replies: 6
    Last Post: 01-30-2006, 03:40 AM
  3. OpenGL - Lights behave strangely
    By Frobozz in forum Game Programming
    Replies: 5
    Last Post: 06-06-2004, 02:00 PM
  4. Two Struct & Class Programs that behave the same
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 07-05-2002, 09:59 AM
  5. Why the function behave like that?
    By zahid in forum C Programming
    Replies: 1
    Last Post: 12-21-2001, 06:56 AM