www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/11/08/09:36:16

From: mert0407 AT sable DOT ox DOT ac DOT uk (George Foot)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Help with Definition: int p=0,d[4]
Date: 8 Nov 1996 13:23:03 GMT
Organization: Oxford University, England
Lines: 45
Message-ID: <55vc7n$t9e@news.ox.ac.uk>
References: <847448023 DOT 11346 DOT 0 AT ciscs19 DOT demon DOT co DOT uk>
NNTP-Posting-Host: sable.ox.ac.uk
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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:

int p,d[4];

it declares 'p' to be an 'int' and 'd' to be a pointer to 5 'int's.

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:

int p=0;
int d[4];

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

--
George Foot

/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ |""""""""""""""""""""""|
>Email: george DOT foot AT merton DOT ox DOT ac DOT uk      < |Snail Mail:(*)        |
>   or: mert0407 AT sable DOT ox DOT ac DOT uk          < | _     George Foot    |
>  Web: http://users.ox.ac.uk/~mert0407/ < |(@)    Merton College |
>  Ftp: mc31.merton.ox.ac.uk (#)         < |~~~~   Oxford OX1 4JD |
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ |______________________|
(#) Theoretically...    ||    (*) Please allow 28 days for delivery

- Raw text -


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