TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: Neil Heller
from: Jasen Betts
date: 2003-07-31 20:05:00
subject: This always drives me cr

Hi Neil.

28-Jul-03 17:44:00, Neil Heller wrote to All


 NH> Given the following code:

 NH> 1)  int * pIntArray = new int[100];

 NH> and

 NH> 2)  int IntArray[100];

 NH> #1 establishes a pointer on the stack which points to an array of
 NH> 100 ints on the heap.

 NH> #2 establishes an array of 100 ints on the stack.

 NH> If I wanted to place a value, say 1000, in the 7th position of #2,
 NH> I would go IntArray[7] = 1000.

 NH> If I wanted to place the same value in the same position of #1,
 NH> how would I go about doing it?

The same way.  arrays are like nonvariable pointers, pointers are like
arrays.

 NH> How would I go about using memset() to set all elements of the
 NH> array to 0?

memset( intarray , 0 , sizeof( int[100] ) ) // works the same for #1 or #2

 -=> Bye <=-

---
* Origin: Success is a journey, not a destination. (3:640/1042)
SEEN-BY: 633/267 270
@PATH: 640/1042 531 954 774/605 123/500 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.