Horje
how to define global array in c++ in a scope Code Example
how to define global array in c++ in a scope
class C {
 int [] x;

 void method A(int size)
 {
   x = new int[size];   // Allocate the array
   for(int i = 0; i < size; i++)
      x[i] = i;         // Initialise the elements (otherwise they contain random data)
   B();
   delete [] x;         // Don't forget to delete it when you have finished
                        // Note strange syntax - deleting an array needs the []
 }

 void method B()
 {
   int n;
   cin >> n;
   cout << x[n];
   // Be warned, if the user inputs a number < 0 or >= size, 
   // you will get undefined behaviour!
  }
}




Cpp

Related
print all substrings in c++ Code Example print all substrings in c++ Code Example
c++ execution time Code Example c++ execution time Code Example
long to string cpp Code Example long to string cpp Code Example
Start mongodb community server Code Example Start mongodb community server Code Example
find an element in vector of pair c++ Code Example find an element in vector of pair c++ Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
13