Search
 
SCRIPT & CODE EXAMPLE
 

CPP

how to make a n*n 2d dynamic array in c++

int** a = new int*[rowCount];
for(int i = 0; i < rowCount; ++i)
    a[i] = new int[colCount];
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

two dimensional dynamic array c++

int ** two_dim_array(int row_num, int col_num)
{
	int **two_dim_array=(int **)malloc(sizeof(int *)*row_num);
    int i, j;
  	for(i=0:i<row_num;i++)
    {
  		two_dim_array[i]=(int *)malloc(sizeof(int)*col_num);
      	for(j=0:j<col_num;j++)
          	two_dim_array[i][j]=0;
    }
  	return two_dim_array;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: functors in c++ 
Cpp :: string.begin() c++ 
Cpp :: c++ friend class 
Cpp :: string substr c++ 
Cpp :: c++ int 
Cpp :: length of array in cpp 
Cpp :: c++ fstream 
Cpp :: how to return char* from function in c++ 
Cpp :: cpp pushfront vector 
Cpp :: for loop c++ 
Cpp :: Accpt array input in single line in cpp 
Cpp :: c++ encapsulation 
Cpp :: c++ int to char* 
Cpp :: stoi() c++ 
Cpp :: sizeof’ on array function parameter ‘arr’ will return size of ‘int*’ [-Wsizeof-array-argument] 
Cpp :: print duplicate characters from string in c++ 
Cpp :: lua table contains 
Cpp :: last character of std::string 
Cpp :: power function c++ 
Cpp :: Find the biggest element in the array 
Cpp :: convert integer to string in c++ 
Cpp :: C++ std::optional 
Cpp :: demonstrate constructor 
Cpp :: how to find the length of an array in cpp 
Cpp :: array of Methods c++ 
Cpp :: how to format decimal palces in c++ 
Cpp :: char to int in c++ 
Cpp :: exponent power of x using c c++ 
Cpp :: prevent getting data from data-tooltip-content tippyjs 
Cpp :: Integer Moves codeforces solution 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =