5 Replies - 253 Views - Last Post: 14 May 2013 - 10:46 PM Rate Topic: -----

#1 nothingme  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 66
  • Joined: 02-November 10

(a+i)= i*i;

Posted 14 May 2013 - 04:46 AM

int *a= new int[10];
    for int (i = 0; i++; i<=9) {
        (a+i)= i*i;
    }


I was wondering what does this line mean -
(a+i)= i*i;


What is the alternative way to do it?
Is This A Good Question/Topic? 0
  • +

Replies To: (a+i)= i*i;

#2 oyyou  Icon User is offline

  • D.I.C Head

Reputation: 27
  • View blog
  • Posts: 184
  • Joined: 26-April 10

Re: (a+i)= i*i;

Posted 14 May 2013 - 04:52 AM

View Postnothingme, on 14 May 2013 - 04:46 AM, said:

int *a= new int[10];
    for int (i = 0; i++; i<=9) {
        (a+i)= i*i;
    }


I was wondering what does this line mean -
(a+i)= i*i;


What is the alternative way to do it?


a[i] = i*i;
Was This Post Helpful? 0
  • +
  • -

#3 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2102
  • View blog
  • Posts: 3,207
  • Joined: 21-June 11

Re: (a+i)= i*i;

Posted 14 May 2013 - 05:08 AM

It doesn't mean anything. It will cause a compilation error because a+i does not produce an lvalue and thus can't be assigned to.

View Postoyyou, on 14 May 2013 - 01:52 PM, said:

a[i] = i*i;


That would be *(a+i) = i*i;.
Was This Post Helpful? 1
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,496
  • Joined: 23-August 08

Re: (a+i)= i*i;

Posted 14 May 2013 - 12:10 PM

This is completely wrong:

for int (i = 0; i++; i<=9) {


It's for (startConditions; endConditions; increment).
Was This Post Helpful? 0
  • +
  • -

#5 buffalobill  Icon User is offline

  • D.I.C Head

Reputation: 21
  • View blog
  • Posts: 188
  • Joined: 08-July 08

Re: (a+i)= i*i;

Posted 14 May 2013 - 09:41 PM

I think its a recursive type statement (where i appears on both sides of the equation).
It means the same as:
a=i(i-1)//if i=3 a=6.
Was This Post Helpful? 0
  • +
  • -

#6 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1072
  • View blog
  • Posts: 4,532
  • Joined: 09-June 09

Re: (a+i)= i*i;

Posted 14 May 2013 - 10:46 PM

Quote

I think its a recursive type statement (where i appears on both sides of the equation).

That doesn't imply that a function is recursive. A recurrence relation is one that is dependent on the sequence of preceding terms.

i.e.
not recursive
f(x) - x = x * x

recursive
f(x) = x * x + f(x-1)
f(0) = 1

This post has been edited by jjl: 14 May 2013 - 10:46 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1