🔥Finding it Damn Hard to Understand C Programming? Learn to code-the right way-with interactive lessons, quizzes & challenges. Build a strong programming base; it's IMPORTANT! Try Programiz PRO for Free: bit.ly/master-c-programming
Well in the quiz,,, u cant create int arr[1][4]={{3,6,9,12}, {2,4,6,8}}; because in arr should be [2][4], so if it would be coded like this, and you will print out arr[1][4], it will choose the second row so {2,4,6,8} but it will print a random number :) @programizstudios
actually the answer is 0 and not random value...random value is generated when extra spaces are available and youre trying to print them....eg...youre given 5 index space to the array and only 2 are filled...then if u try to access the 4th index...u get random value...in this case it is different...
Q. Which value will we get when we print arr[1][4] from the following array? int arr[1][4] = { {3, 6, 9, 12}, {2, 4, 6, 8} }; A.12 B. 8 C. 0 D. Random Value
The correct answer is D. The array was initialized as "arr[1][4]" which is incorrect, it should be "arr[2][4]". This causes only the first array to be recognized by the program, so when we try to print "arr[1][4]" (which should be "arr[2][4]" if the array was initialized properly) the value does not exist, therefore a random value will be printed.
At first i thouhght the answer was B(8), I then realised that int arr [1][4] is not present in the array elements we have been provided with. [1][4] in this case means that there's only one array with 4 elements in the array . However the numbers displayed {3, 6, 9, 12} , {2, 4, 6, 8} represents two arrays with each having 4 elements, hence the proper representations should be int arr[2][4] = {3, 6, 9, 12} , {2, 4, 6, 8} . hence for the quiz provided you will get 0 example #include int main(){ int arr[2][4] = {{3, 6, 9, 12} , {2, 4, 6, 8}}; //two arrays with 4 elements in each array// printf("%d ",arr[1][3]); // [0 1 - one is second i.e second array], [0 1 2 3 - 3 is fourth] hence the command asks us to print the fouth element of the second array// return 0; } The output is 8
@@canhtranhLuat the answer is zero mate. Am sure you didn't read the whole comment..i said at first i thought the answer was 8, but after working it out..i.realized it's 0
//Which value will we get when we print arr[1][4] from the following array? int arr[1][4] = { {3, 6, 9, 12}, {2, 4, 6, 8} } #include int main() { int arr[2][4] = {{3, 6, 9, 12}, {2, 4, 6, 8}}; for(int i=0; i
in the above array the size is exceeded because the actual size is arr[1][3] so the the above array pics the value zero because if the array[1][4] has no value to pick by default it will pick zero
#include int main(){ double arOfAr[3][5]; printf("Now we will create an array of arrays ! "); for (int p = 0; p < 3; p++){ int count1 = p + 1; for (int d = 0; d < 5; d++){ int count2 = d + 1; printf("Enter your '%d' value of your '%d' array: ", count2, count1); scanf("%lf", &arOfAr[p][d]); } } printf("The values you have chosen are: "); for (int p = 0; p < 3; p++){ for (int d = 0; d < 5; d++){ printf("%lf ", arOfAr[p][d]); } } return 0; }