Need a project done?

C++ Programming Developer

Search This Blog

Pass 2-d array to function which will initialize all of its elements to Zero

/*
Write a program to perform the following functions.
Declare a 5*4 int array in the main ().
Pass it to another function that will initialize all of its elements to zero,
without using the subscript operator [ ].
*/




#include <iostream>
using namespace std;
void zero( char [][4], int, int);
int main()
{
char a[5][4];

zero(a,5,4);

//Printing array
for (int r=0; r<5; r++)
{
for (int c=0; c<4; c++)
cout << a[r][c];

cout << endl;
}
return 0;
}

void zero (char a[][4], int r, int c)
{
for (int j = 0; j<4; j++)
for (int i = 0; i<5; i++)
{
*(*(a+i)+j) = '0';
}
}

"Don't let anyone ever make you feel like you don't deserve what you want."