www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/11/14/07:58:11

From: brennan AT mack DOT rt66 DOT com (Brennan "The Rev. Bas" Underwood)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Help with Definition: int p=0,d[4]
Date: 10 Nov 1996 17:04:52 -0700
Organization: Rasterfari
Lines: 54
Message-ID: <565qj4$d85@mack.rt66.com>
References: <847448023 DOT 11346 DOT 0 AT ciscs19 DOT demon DOT co DOT uk> <55vc7n$t9e AT news DOT ox DOT ac DOT uk>
NNTP-Posting-Host: mack.rt66.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

In article <55vc7n$t9e AT news DOT ox DOT ac DOT uk>,
George Foot <mert0407 AT sable DOT ox DOT ac DOT uk> wrote:
>BDC Client Team (cs19 AT cityscape DOT co DOT uk) wrote:
>
>: int p=0,d[4]
>
>: It is obviously defining an integer variable 'p' and assigning a start value
>: to it - can anyone help me with the right-hand side of the '=' sign ?  
>: There is no reference to a variable 'd' in the rest of the code, so I assume 
>: that, in this case, 'd'is recognized by the compiler as a function/constant 
>: of some kind.
>
>You'll kick yourself...
>
>In C, if you write:
>
>int p,d;
>
>it declares 'p' and 'd' to be of type 'int'. If you write:

YES it does.

>int p,d[4];
>
>it declares 'p' to be an 'int' and 'd' to be a pointer to 5 'int's.

NO it does not. 4 ints!

>In C++, writing:
>
>int p=0,d[4];
>
>declares 'p' as and 'int' and sets it to zero, and also declares 'd' to 
>be a pointer to 5 'int's. It's the same as:

4 ints! And d isn't a pointer, but 'd' specified alone is the location
of the first array item. If it was a pointer, you could reassign it.

>int p=0;
>int d[4];

YES it does.

>
>The '=' sign has a higher precedence than the ','.

Guh? Don't confuse with ',' in a mathematical expression.


--Brennan
-- 
 brennan AT rt66 DOT com |  "They are the dead, brought to simulated life by our
Riomhchlaraitheoir|  electro-guns."
   Rasterfarian   |  <http://brennan.home.ml.org>

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019