C Puzzle -Printf

This is a discussion on C Puzzle -Printf within the C Programming forums, part of the General Programming Boards category; How output from below printf was "Hello! how is this? super That is C! " Code: #include <stdio.h> int main() ...

  1. #1
    C is Sea. I know a drop! ganesh bala's Avatar
    Join Date
    Jan 2009
    Location
    Bangalore
    Posts
    58

    Wink C Puzzle -Printf

    How output from below printf was

    "Hello! how is this? super
    That is C! "


    Code:
        #include <stdio.h>
      int main()
      {
        int a=3, b = 5;
    
        printf(&a["Ya!Hello! how is this? %s\n"], &b["junk/super"]);
        printf(&a["WHAT%c%c%c  %c%c  %c !\n"], 1["this"],
           2["beauty"],0["tool"],0["is"],3["sensitive"],4["CCCCCC"]);
        return 0;
      }
    This is taken from A Quiz
    Last edited by ganesh bala; 02-16-2009 at 10:56 PM.

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    Here's a simpler example using the same principal -
    Code:
    int a[5] = { 1, 2, 3, 4, 5 };
    int i = 3;
    printf("%d", i[a]); /* NOT a typo */

  3. #3
    C is Sea. I know a drop! ganesh bala's Avatar
    Join Date
    Jan 2009
    Location
    Bangalore
    Posts
    58
    What about this??



    printf(&a["Ya!Hello! how is this? %s\n"], &b["junk/super"]);

    &a["WHAT%c%c%c %c%c %c !\n"]

  4. #4
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    Before throwing strings into the question, do you understand my simpler example?

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,420
    http://c-faq.com/aryptr/joke.html
    I hope this wasn't a question from anyone serious (like say a prospective employer)
    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. IF CONDITION plese help
    By birumut in forum C Programming
    Replies: 12
    Last Post: 03-06-2009, 08:48 PM
  2. making it portable.....?
    By ShadeS_07 in forum C Programming
    Replies: 11
    Last Post: 12-24-2008, 08:38 AM
  3. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 04:42 PM
  4. Simple C question: user input to repeat a loop
    By evernaut in forum C Programming
    Replies: 2
    Last Post: 11-18-2006, 08:23 AM
  5. Drawing tables in C
    By stanoman in forum C Programming
    Replies: 5
    Last Post: 10-09-2003, 10:14 AM

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