Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ allocate and free dynamic 2d array

// allocate
int** matrix = new int*[rowCount];
for(int i = 0; i < rowCount; i++)
    matrix[i] = new int[colCount];

// free
for(int i = 0 ; i < rowCount; i++)
    delete[] matrix[i];	// delete array within matrix
delete[] matrix;	// delete actual matrix
Comment

declaring 2d dynamic array c++

int** arr = new int*[10]; // Number of Students
int i=0, j;
for (i; i<10; i++) 
	arr[i] = new int[5]; // Number of Courses
/*In line[1], you're creating an array which can store the addresses
  of 10 arrays. In line[4], you're allocating memories for the 
  array addresses you've stored in the array 'arr'. So it comes out 
  to be a 10 x 5 array. */
Comment

PREVIOUS NEXT
Code Example
Cpp :: bit c++ 
Cpp :: c++ map iterator 
Cpp :: convert int to string c++ 
Cpp :: c++ kruskal algorithm 
Cpp :: c++ rand 
Cpp :: how to check is some number is divisible by 3 in c++ 
Cpp :: how to add numbers in c++ 
Cpp :: how to traverse a linked list in c++ 
Cpp :: check if float has decimals c++ 
Cpp :: how to compare lower case character to uppercase cpp 
Cpp :: change abstract title name latex 
Cpp :: syntax c++ 
Cpp :: cpp case 
Cpp :: in c++ the default value of uninitialized array elements is 
Cpp :: c++ sort vector 
Cpp :: Rick Astley - Never Gonna Give You Up 
Cpp :: sleep system function linux c++ 
Cpp :: how to declare a function in c++ 
Cpp :: string to long integer c++ 
Cpp :: how to make a typing effect c++ 
Cpp :: cpp insert overload operator 
Cpp :: strlen in c++ 
Cpp :: c++ template function 
Cpp :: built in factorial function in c++ 
Cpp :: delete dynamic array c++ 
Cpp :: create copy constructor c++ 
Cpp :: how to use cout function in c++ 
Cpp :: c++ logger class example 
Cpp :: how to print a text in c++ 
Cpp :: Palindrome String solution in c++ 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =