Thread: Need Help in Understanding this Code

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    29

    Question Need Help in Understanding this Code

    Hi guys. I got this code as a part of large one. I'm not able to understand its proper working.
    Code:
    int main()
    {
    int a,b=10;
    a="" [b+++11];  //Need Explanation
    printf(" %d ",a);
    a="Hello World" [b+++11];  //Need Explanation
    printf(" %d ",a);
    return 0;
    }
    I mentioned comment in the code where I need explanation. This code will print two different values of a, but I'm not getting the working of initialization process as its pretty new to me.
    Code:
    a="Hello" [b+++11];
    If anyone can explain it to me then I shall be highly great full.
    Thanks in advance.

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    I think that this equivalent to this
    Code:
     b++ + 11
    Edit->
    Code:
    a="Hello World" [b+++11];
    It takes from the string the 'b++ + 11'-th character and stores it as a decimal to integer a
    Last edited by std10093; 09-04-2012 at 04:18 PM.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Exactly what I was going to explain.

    One important point worth nothing though, both of those are buffer overruns!

    Where did you get that crap code?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    Registered User
    Join Date
    Mar 2012
    Posts
    29
    Thanks guys. Seems the explanation is working fine with different values.
    Well I got this code while analyzing an obfuscation.

    Thanks a ton.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help to understanding the code
    By zbonzbon in forum C Programming
    Replies: 10
    Last Post: 02-13-2011, 10:23 PM
  2. Need some help understanding the following code
    By GTTDi in forum C Programming
    Replies: 1
    Last Post: 10-15-2010, 07:28 AM
  3. code understanding
    By elwad in forum C Programming
    Replies: 5
    Last Post: 04-18-2009, 06:57 AM
  4. I need help understanding this code
    By Sshakey6791 in forum C++ Programming
    Replies: 5
    Last Post: 12-23-2008, 02:49 PM
  5. help me understanding this code
    By apfelsaft in forum C Programming
    Replies: 2
    Last Post: 01-14-2004, 04:46 PM