Awesome program with pointers.

This is a discussion on Awesome program with pointers. within the General Discussions forums, part of the Community Boards category; Just saw this and thought other people might enjoy it. If you can't tell from the code, I strongly recommend ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    32

    Awesome program with pointers.

    Just saw this and thought other people might enjoy it. If you can't tell from the code, I strongly recommend compiling/running.

    Code:
    #include<stdio.h>
    
    
    char *c[] = { "ENTER", "NEW", "POINT", "FIRST" };
    char **cp[] = { c+3, c+2, c+1, c };
    char ***cpp = cp;
    
    
    main()
    {
        printf("%s", **++cpp);
        printf("%s ", *--*++cpp+3);
        printf("%s", *cpp[-2]+3);
        printf("%s\n", cpp[-1][-1]+1);
        return 0;
    }
    EDIT: I did NOT write this.
    Last edited by Mark Labarbara; 01-02-2012 at 09:19 PM.

  2. #2
    Chi! whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    8,189
    Pointers can be fun but the author forgot to make it well defined.
    *--*++cpp+3
    At least I'm pretty sure, 'cause expressions like this require the variable to be modified twice.

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    32
    Quote Originally Posted by whiteflags View Post
    Pointers can be fun but the author forgot to make it well defined.
    *--*++cpp+3
    At least I'm pretty sure, 'cause expressions like this require the variable to be modified twice.
    I have no idea, I am pretty new to programming.

    Either way, when you compile and run it, the output is pretty sweet

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,623
    Quote Originally Posted by whiteflags
    Pointers can be fun but the author forgot to make it well defined.
    *--*++cpp+3
    At least I'm pretty sure, 'cause expressions like this require the variable to be modified twice.
    It looks well defined because the dereferencing causes different objects to be modified.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5

    Join Date
    May 2005
    Posts
    1,042
    Gave me a chuckle.
    I'm not immature, I'm refined in the opposite direction.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Awesome C++ College Textbook
    By HarleyJohn in forum C++ Programming
    Replies: 4
    Last Post: 04-29-2009, 11:35 AM
  2. Awesome?
    By pianorain in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 02-01-2005, 04:08 PM
  3. this is awesome
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 02-27-2004, 02:45 PM

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