(1) True or False A: An array index in not allowed to be a real number, except w
ID: 3887822 • Letter: #
Question
(1) True or False A: An array index in not allowed to be a real number, except when the elements in the array are of type double. B: In C, we can access index positions beyond the array size. That is, it is legal to have index values larger than the array size. C: In using 2D arrays in a function, definition. we always have to specify the size of the two dimensions of the array as part of the function D: In C, an array is passed by reference. However, passing an element of an array is typically by value, rather than by reference (2) Write a program that uses a function called init2DO to initialize a 2D array. The function should and resets the elements to zero. Write a second function print2Darray0 that accepts th containing the elements in the array. Your program should show the following: the 2D array, and prints out a table array as input, (i) prototype declarations for each function (ii) function calls in main (iii) function definitions for the two programsExplanation / Answer
A. No. Array index has to be integer because accessing different elements need integer airtmatic operations.
B.No . It is not legal to have indexes beyond the size of the arry.
C. No. we just need to give the column size as it is required to set the size of the array.
D. The array is passed by refrence. The address of the first element is passed and there is no copying of vaues of individual elements.
#include<stdio.h>
void init2D(int d[][4]){
int i,j;
for (i = 0; i<3; i++){
for(j = 0; j<4; j++)
d[i][j] = 0;
}
}
void print2D(int d[][4]){
int i,j;
for (i = 0; i<3; i++){
for(j = 0; j<4; j++)
printf("%d ",d[i][j]);
printf(" ");
}
}
int main(){
int d[3][4];
init2D(d);
print2D(d);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.