Thread: What does accesing a numeric literal with brackets means?

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    2

    Question What does accesing a numeric literal with brackets means?

    Hello, I spotted this at an International Obfuscated C Code Contest entry, and I don't understand what it means.

    The question is: What the heck does something like this means and how the heck does it compiles?:

    Code:
    #include<iostream>
    using namespace std;
    int main()
    {
        char *a;
        cout<<35[a]<<endl; //This is the line I don't get at all
        return 0;
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    p[i] = *(p+i);
    p +i = i +p;
    so p[i] = i[p];
    c-faq

  3. #3
    Registered User
    Join Date
    Jun 2010
    Posts
    2
    Oh, I see. I didn't though that would be on the FAQ, so I didn't searched it hard enough. My bad

    Thanks!

  4. #4
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    It's still simple actually
    Code:
      0[ strchr(p,'\n') ] = '\0';     // combine with function !

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Until strchr returns NULL
    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.

  6. #6
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    lol, that's just an example!

  7. #7
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    lol @Salem... why are you always such a purist
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

Popular pages Recent additions subscribe to a feed

Tags for this Thread