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

function for 2d dynamic array

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 :: c++ how to check whether a file exists? 
Cpp :: c++ unordered_map check if key exists 
Cpp :: c++ string remove last character 
Cpp :: c++ competitive programming mst 
Cpp :: capitalize first letter c++ 
Cpp :: check if an element is in a map c++ 
Cpp :: c++ check if string is empty 
Cpp :: run c++ file putty 
Cpp :: how to do (binary) operator overloading in c++ 
Cpp :: how to check size of file in c++ 
Cpp :: how to split a string into words c++ 
Cpp :: character array to string c++ stl 
Cpp :: C++ switch - case - break 
Cpp :: how to do nCr in c++ 
Cpp :: string to int in c++ 
Cpp :: iterate over map c++17 
Cpp :: how to get size of char array in c++ 
Cpp :: delete one specific character in string C++ 
Cpp :: vector.find() 
Cpp :: c++ segmented sieve primes 
Cpp :: overload stream extract cpp 
Cpp :: how to get the first element of a map in c++ 
Cpp :: c++ do while loop 
Cpp :: swapping of two numbers 
Cpp :: C++ String Length Example 
Cpp :: check if set contains element c++ 
Cpp :: rotate array cpp 
Cpp :: c++ double is nan 
Cpp :: insert a character into a string c++ 
Cpp :: how to add external library in clion 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =