delorie.com/archives/browse.cgi | search |
Mailing-List: | contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm |
Sender: | cygwin-owner AT sourceware DOT cygnus DOT com |
Delivered-To: | mailing list cygwin AT sourceware DOT cygnus DOT com |
Message-ID: | <19990725214317.29753.qmail@hotmail.com> |
X-Originating-IP: | [209.209.164.20] |
From: | "Ward Correll" <wardless AT hotmail DOT com> |
To: | cygwin AT sourceware DOT cygnus DOT com |
Subject: | Cygwin Memory Handling in Arrays |
Date: | Sun, 25 Jul 1999 17:43:15 EDT |
Mime-Version: | 1.0 |
How does Cygwin manage memory in this c++ program? I thought that either the arrays sentinelOne[3] or sentinelTwo[3]would have been over written containing the value from writting past the end of the array TargetArray[25]. What happened here? #include <iostream.h> int main() { // sentinels long sentinelOne[3]; long TargetArray[25]; // array to fill long sentinelTwo[3]; int i; for (i=0; i<3; i++) sentinelOne[i] = sentinelTwo[i] = 0; for (i=0; i<25; i++) TargetArray[i] = 0; cout << "Test 1: \n"; // test current values (should be 0) cout << "TargetArray[0]: " << TargetArray[0] << "\n"; cout << "TargetArray[24]: " << TargetArray[24] << "\n\n"; for (i = 0; i<3; i++) { cout << "sentinelOne[" << i << "]: "; cout << sentinelOne[i] << "\n"; cout << "sentinelTwo[" << i << "]: "; cout << sentinelTwo[i]<< "\n"; } cout << "\nAssigning..."; for (i = 0; i<=26; i++) TargetArray[i] = 20; cout << "\nTest 2: \n"; cout << "TargetArray[0]: " << TargetArray[0] << "\n"; cout << "TargetArray[24]: " << TargetArray[24] << "\n"; cout << "TargetArray{25}: " << TargetArray[25] << "\n"; cout << "TargetArray[26]: " << TargetArray[26] << "\n\n"; for (i = 0; i<3; i++) { cout << "sentinelOne[" << i << "]: "; cout << sentinelOne[i]<< "\n"; cout << "sentinelTwo[" << i << "]: "; cout << sentinelTwo[i]<< "\n"; } return 0; } ============================OUTPUT=================================== Test 1: TargetArray[0]: 0 TargetArray[24]: 0 sentinelOne[0]: 0 sentinelTwo[0]: 0 sentinelOne[1]: 0 sentinelTwo[1]: 0 sentinelOne[2]: 0 sentinelTwo[2]: 0 Assigning... Test 2: TargetArray[0]: 20 TargetArray[24]: 20 TargetArray{25}: 20 TargetArray[26]: 20 sentinelOne[0]: 0 sentinelTwo[0]: 0 sentinelOne[1]: 0 sentinelTwo[1]: 0 sentinelOne[2]: 0 sentinelTwo[2]: 0 _______________________________________________________________ Get Free Email and Do More On The Web. Visit http://www.msn.com -- Want to unsubscribe from this list? Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |