Thread: simple scope question

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Hi,

    But the array example works: the output is 1. My question is why? Why is the array example like assigning a simple type and not like assigning a class object? In the array example, it seems to me you are assigning a pointer to the outer variable which points to an address in memory which contains the array, and then the array goes out of scope, so why can you still access the array? Shouldn't it no longer exist?

    Variables are just blocks of memory that hold values. When you assigned outerA to i (outerA = i; ) the value in i's block was put into outerA's block. Once you get out of that if statement, i's block goes away, but the value is still stored in A's block. Same thing with outerB and the array.
    Applying that to the array, shouldn't outerB's block of memory contain the address of the inner array?
    Last edited by 7stud; 01-29-2005 at 04:56 AM.

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    It doesnt exist. It is just dumb luck that it works.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 12:15 PM
  2. A simple question about scope
    By dwylie in forum C Programming
    Replies: 3
    Last Post: 12-10-2004, 01:16 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. simple fgets question
    By theweirdo in forum C Programming
    Replies: 7
    Last Post: 01-27-2002, 06:58 PM
  5. Scope question
    By mikebrewsj in forum C++ Programming
    Replies: 1
    Last Post: 01-17-2002, 04:47 PM