www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/05/07/15:45:17

From: "Michael Stewart" <mike AT reggin DOT freeserve DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Using pointers
Date: Fri, 7 May 1999 08:42:47 +0100
Organization: USENET UK
Lines: 24
Message-ID: <7gu5bt$u5e$1@hagen.cloud9.co.uk>
References: <Pine DOT BSF DOT 3 DOT 96 DOT 990507090735 DOT 15546B-100000 AT studenti DOT ing DOT unipi DOT it>
NNTP-Posting-Host: hgty.capgemini.co.uk
X-Trace: hagen.cloud9.co.uk 926062781 30894 194.42.240.2 (7 May 1999 07:39:41 GMT)
X-Complaints-To: abuse AT usenet DOT co DOT uk
NNTP-Posting-Date: 7 May 1999 07:39:41 GMT
X-Newsreader: Microsoft Outlook Express 4.72.3155.0
X-Mimeole: Produced By Microsoft MimeOLE V4.72.3155.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

GiovanniB wrote in message ...
>
>   When I declare a pointer (i.e. int* myptr) it's possible to use it in
>this way :
> for(int i = 0; i < n; i++)
> {
> myptr[i] = somenumber;
> }
>where n is a number big than biggest int ?


You can indeed treat a pointer as an array, in a sense thats what it is.
Just remember to allocate the memory.

/* C */
myptr = (int *) malloc (n * sizeof (int));

/* C++, I think this is how to do it */
myptr = new (int)[n];


Michael Stewart


- Raw text -


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