print_array( cout,  ai, 5);  
in this code, does ai get changed to p1 in all cases

Robert Ryan <[EMAIL PROTECTED]> wrote:                               original 
code to be used as prototype
 
 void print_array(ostream& os, int* ai, int n)
 {
           for(int i=0; i<n; ++i)
            os << ai[i];
 }    const int max = 5;
                    int i, n = 0;
  int f(int n)
 {
             int *a=new int[5];
             int ai[5];
             int* p = &ai[5]; 
 
 ai[0]=1, ai[1]=2, ai[2]=3, ai[3]=4, ai[4]=5;
             print_array(cout,  ai, 5);
             return 0;
 }
          
 int main( )
 {
       f(0);
         
   }
   
 
 Robert Ryan <[EMAIL PROTECTED]> wrote:                               the 
problem states: allocate an int in C++, initialize it to 7 and assign it to a 
variable p1
                                  print out the value of p1 and of the ints it 
points to
  
  Jacob Lund Fisker <[EMAIL PROTECTED]> wrote:
            Not sure what you intend to do.
  
  "new" allocates
  "=" assigns
  "int,double,float, ..." initializes.
  
  So for instance ... int *i = new int(5);
  
  new allocates space for an int on the heap, assigns the value 5 to that 
  space and returns the address which is assigned to a pointer called i 
  that is initialized to that address. Phew!
  
  On Nov 13, 2007, at 6:41 PM, Robert Ryan wrote:
  
  > allocate an int: int i =0;
  > initialize an int: int i = 5;
  > assign it to variable p1: p1 = 5;
  >
  > or is it this:
  >
  > int i =new int[ ];
  > int p1[5];
  > int* p1 = &p1[5];
  >
  > is this right
  > bob ryan
  >
  >
  > ---------------------------------
  > Be a better sports nut! Let your teams follow you with Yahoo Mobile. 
  > Try it now.
  >
  > [Non-text portions of this message have been removed]
  >
  >
  >
  > To unsubscribe, send a blank message to 
  > <mailto:[EMAIL PROTECTED]>.
  > Yahoo! Groups Links
  >
  >
  >
  
  ---------------------------------
  Be a better sports nut! Let your teams follow you with Yahoo Mobile. Try it 
now.
  
  [Non-text portions of this message have been removed]
  
  
      
                                
 
 ---------------------------------
 Be a better sports nut! Let your teams follow you with Yahoo Mobile. Try it 
now.
 
 [Non-text portions of this message have been removed]
 
 
     
                               

       
---------------------------------
Be a better pen pal. Text or chat with friends inside Yahoo! Mail. See how.

[Non-text portions of this message have been removed]

Reply via email to