Thread: help me figure out a part of this short code...about pointers

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    42

    help me figure out a part of this short code...about pointers

    Code:
    #include<stdio.h>
    
    int main(void)
    {
     int x = 0;
     int z[] = {0,1,4,9,16,25,36,49,64,81};
     int *p = z
    
    x= *(p+9) /*this will be 81*/ + *(p+3) /*this will be 9*/ + (10**(z+1)); /* i have no clue for this one*/
    printf("x= %i\n", x);
    
    return 0;
    
    }

  2. #2
    Registered User
    Join Date
    Dec 2011
    Location
    Seattle area
    Posts
    4
    That was a tricky one, because to me, ** looked like it meant a power operator, as it does in Fortran and some other languages. I thought maybe there was a typing error in the code example above with a space missing so that it should have read

    + 10* *(z+1)

    It turns out, space or not, it comes out to the same number without an overflow.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    *(z+1) is the dereferenced 2nd element in z.

    Correct, Sonny_E ** is does not exist as 'power' in C.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Short and Sweet Part 2.
    By dispatch4599 in forum C++ Programming
    Replies: 16
    Last Post: 03-03-2008, 12:29 AM
  2. Very short code tt never work...please help
    By newbie1234 in forum C Programming
    Replies: 7
    Last Post: 05-23-2006, 11:46 PM
  3. A Short History of Computing Part I
    By icarus in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-15-2002, 03:01 PM
  4. help with this short code on my quiz..
    By vtlo99 in forum C++ Programming
    Replies: 2
    Last Post: 03-01-2002, 08:17 AM
  5. how will this short c++ code look in pure c?
    By dune911 in forum C Programming
    Replies: 8
    Last Post: 10-19-2001, 11:21 AM