Wednesday, October 2, 2019

How to Dynamically allocate memory to 2D array in c++?

There are multiple ways to allocate memory to 2D array dynamically. I will discuss few of theme here.

1) By creating the pointer of pointers of specific data types:
#include<iostream>
void free2DArrayMemory(int **, int);
using namespace std;
int main()
{
int row=3, col=4;
int **arr = new int*[row];
       //int **arr = (int **)malloc(sizeof(int)*row); //For C style memory allocation

for(int i=0; i<row; i++)
{
       arr[i] = new int[col];
               //arr[i] = (int*) malloc(sizeof(int)*col); // For C style
         }

int count = 10;
for(int r=0;r<row;r++)
for(int c=0;c<col;c++)
arr[r][c] = count++;

for(int r=0;r<row;r++)
{ for(int c=0;c<col;c++)
{
cout<<arr[r][c]<<" ";
//cout<<*(*(arr+r)+c)<<" ";
}
cout<<endl;
}

      free2DArrayMemory(arr,col);
return 1;
}

void free2DArrayMemory(int **arr, int col)
{
if(!arr)
return;

for(int i;i<col;i++)
{
delete []arr[i];
//free(arr[i]); //For C Stype
}
delete []arr;
//free(arr); //For C
}
-----------------------------------------------------------------------------------------

2) By creating the array of pointers:
#include<iostream>
using namespace std;
int main()
{
int row=3, col=4;
int *arr[row];

for(int i=0;i<row;i++)
arr[i] = new int[col];

int count = 10;
for(int r=0;r<row;r++)
for(int c=0;c<col;c++)
arr[r][c] = count++;

for(int r=0;r<row;r++)
{ for(int c=0;c<col;c++)
{
//cout<<arr[r][c]<<" ";
cout<<*(*(arr+r)+c)<<" ";
}
cout<<endl;
}
      free2DArrayMemory(arr,col);
return 1;
}

-----------------------------------------------------------------------------------------

3) 

Thursday, January 4, 2018

*****Killing of Mother-Board/Circuit Board without being caught*****
There are many ways by which one can kill (Making non-functional) the Computer/Laptop without being caught. As I believe for every problem there are multiple solutions and one should choose best of them known to him. One might think that knowing only the best thing is enough, but I would suggest to know every solution as it helps in better understanding, comparing of solutions and choosing the best solution. It will add an extra confidence in you.
I am listing here few of theme here in sequence best first (best known to me):-

* Static Electricity ::
           Static electricity is generated when two non metallic body rubbed to each other.   The way to kill a circuit board without letting any one know. :: Challenge :- How to generate SE.

* By overheating of CPU::
Binding the CPU in blanket and run games or videos which uses more RAM and Processor, so it will produce more heat inside. There will a level reach when heat generated inside will burn out the processor or any one of the circuit.

* Static electricity can be produced by different methods. One of the powerful method is to use Condensor.

* Open the PC/Laptop and pull any one connector which is difficult to reach. Best you can pull the display connector. In this case the computer will turn, you will the blinking of lights of Hard disk reading, charging, cpu fan running etc. But no light in screen. It may give a issution that there can be a multiple reasons for it. The general reason when light did not come in the screen is Bad RAM. Then ther may be the reason of faulty display adapter etc. So just I want to say is that if display is not comming there can be multiple reasons for it. So it will be difficult to identify the actual reason.

* Disinfect the BIOS. Upload any unsupportive bios and disinfect it.

* Wave a magnet over BIOS chip.

* Shot ciruit the PCI express slot with few wires.