All of the questions are based on the C objecet oriented lan

All of the questions are based on the C++ objecet oriented language

1) Why might it be better to store data in an array rather than use separate variable names?

2) Describe the process of passing an array to a function.

3) Under what circumstances might you use a two-dimensional array?

Solution

1)Ans:If all vaiables are of same data type then it is better to store them in array.Because array is collection of similar elements.It stores the elements in continuous memory so that memory allocation is done properly.We can access data using index instead of name.If data is too large then array is always useful.

==============================================================

2)Array is always paased by pointer to function.Eventhough we pass as function(data_type arr[] ) or function(data_type *arr );

Type 1:

void Fun(int a[])

{

}

main()

{

int a[]={1,2,3};

Fun(a);

}

Type 2:

void Fun(int* a)

{

}

main()

{

int a[]={1,2,3};

Fun(a);

}

Also there is

Type 3:if size is mentioned

void Fun(int a[3])

{

}

main()

{

int a[]={1,2,3};

Fun(a);

}

When pass array to function it always send the base address of array

================================================================================

3)We can 2D array when we want to show result in table format i.e. row-column format.If we want perfotm dataset operations then we can use it.Dataset can be anything such as servey information of families,survey of region etc.

2D array are also represent images in binary form i.e. in the form of 0 and 1.

All of the questions are based on the C++ objecet oriented language 1) Why might it be better to store data in an array rather than use separate variable names?
All of the questions are based on the C++ objecet oriented language 1) Why might it be better to store data in an array rather than use separate variable names?

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site