delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/04/06/07:46:23

Message-ID: <38EC60B9.187BB7F7@videotron.ca>
From: Trancelucid <trancelucid AT videotron DOT ca>
X-Mailer: Mozilla 4.7 [en] (Win98; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: pointers and arrays
References: <emRG4.2308$bh DOT 24017 AT typhoon DOT nyroc DOT rr DOT com>
Lines: 20
Date: Thu, 06 Apr 2000 06:02:33 -0400
NNTP-Posting-Host: 24.201.20.12
X-Complaints-To: abuse AT videotron DOT net
X-Trace: weber.videotron.net 955014853 24.201.20.12 (Thu, 06 Apr 2000 05:54:13 EDT)
NNTP-Posting-Date: Thu, 06 Apr 2000 05:54:13 EDT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Bob wrote:
> 
> Is it legal in c++ to declare a pointer to a multi-dimensional array on the
> free space? ie.
>      short* grade = new short[gradeNum][studentNum];
> when I try this line I get a error of "initialization to 'short int *' from
> 'short int (*)[((studentNum - 1) + 1)]'
> thanks

short *grade = new short[studentNum];  // pointer to array
short **grade = new short[gradeNum][studentNum];  // pointer to double
array

A pointer can be declared just like an array if you want to (in fact, an
array *is* a pointer)... eg: short grade[][] = new
short[gradeNum][studentNum];

HTH,
	.(Trancelucid).
	  .  Jaune  .

- Raw text -


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