Why does it behave so

This is a discussion on Why does it behave so within the C Programming forums, part of the General Programming Boards category; HI, Plz let me know, why this program behave so. Rgds, madhu...

  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
    Attached Files Attached Files

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,344
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,344
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 02: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, 05:56 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21