Search
 
SCRIPT & CODE EXAMPLE
 

CPP

dynamic memory c++

#include<iostream> //c++
#include<stdio.h> // c

C++:
	int* array = new int[n]; // одномерный массив

	free(array);      	 //можно также использовать delete(array); (освобождение памяти)




	int** array = new int*[n]; //двумерный массив (n строк)
	for (int i = 0; i < n; i++) {
		array[i] = new int[m];   	            //(m столбцов)
	}
	
	 for (int i = 0; i < n; i++)      //освобождение памяти
        delete[] array[i];
    delete [] array;

C:

    int**array = (int**)malloc(n * sizeof(int*));
    for (i = 0; i < n; i++) {
        array[i] = (int*)malloc(n * sizeof(int));
    }

     for (i = 0; i < n; i++)
        free(array[i]);               //освобождение памяти
     free(array);          



     int* array = (int*)malloc(n * sizeof(int));   //одномерный массив
     free(array);                                  //освобождение памяти

Comment

dynamic memory in c++

#include <iostream>

int main()
{
  int* ptr = new int(5);
  
  int* arr = new int[3];
  arr[0] = 96;
  arr[1] = 45;
  arr[2] = 72;
  
  std::cout << *ptr << "
";// output: 5
  
  for (int i = 0; i < 3; i++)
  {
    std::cout << arr[i] << " ";
  } // output: 96 45 72
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: declare class c++ 
Cpp :: c++ pointers 
Cpp :: c++ vector operations 
Cpp :: memset c++ 
Cpp :: malloc 2d array cpp 
Cpp :: c++ itoa 
Cpp :: activity selection problem 
Cpp :: C++ Syntax for Passing Arrays as Function Parameters 
Cpp :: remove duplicates from sorted list solution in c++ 
Cpp :: Check whether the jth object is in the subset 
Cpp :: vsearch c program stdlib 
Cpp :: c++ include difference between quotes and brackets 
Cpp :: c++c 
Cpp :: in built function to find MSB in cpp 
Cpp :: OpenCV" is considered to be NOT FOUND 
Cpp :: Bit Tricks for Competitive Programming c ++ 
Cpp :: fabs c c++ 
Cpp :: c++ vector move element 
Cpp :: 0-1 knapsack problem implementation of code input array 
Cpp :: how to create a custom event in ue4 c++ 
Cpp :: c++ text between substrings 
Cpp :: turn it codechef solution in c++ 
Cpp :: PUBG_APIKEY=<your-api-key npm t 
Cpp :: powershell script query mssql windows authentication 
Cpp :: how to use #define c++ 
Cpp :: Buy 2 Get 1 Free codechef solution in c++ 
Cpp :: set precision on floating numbers 
Cpp :: what is stdoutread in c++ 
Cpp :: The smallest element from three 
Cpp :: qt unhandled exception handler 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =