Quiz on Arrays in C++
Any programming language would have an array as it would be a series of related items stored at contiguous memory locations and their elements could be accessed randomly at random locations through variables and indexes. During the upcoming quiz, we will test your understanding of the C++ Arrays. Good Luck!
0 of 15 Questions completed Questions: You have already completed the quiz before. Hence you can not start it again. Quiz is loading… You must sign in or sign up to start the quiz. You must first complete the following: 0 of 15 Questions answered correctly Your time: Time has elapsed You have reached 0 of 0 point(s), (0) Earned Point(s): 0 of 0, (0) #include <iostream> using namespace std; int main() { int i; int arr[6] = { 10, 20, 30, 40 }; // cout<<arr[5]; for(i=0;i<6;i++) cout<<arr[i]<<” “; return 0; } #include <iostream> using namespace std; int main() { int c = 1,i,temp,n=3,j; int arr[3][3]={11,12,13,14,15,1}; for(i=1;i<n;i++) { for(j = 1;j<n;j++) { temp = arr[i][j] + c; arr[i][j] = arr[j][i]; arr[j][i] = temp – c; } } for(i = 0; i<n;i++) for(j = 0;j<n;j++) cout<< arr[i][j] <<” “; return 0; } Int arr={1,2,3,1,2,3,4,5,1,2}; What is the value of the element at arr[3][0] in the following program? #include<iostream> using namespace std; int main() { int arr[5][2] = {{0,1}, {2,3}, {4,5}}; for (int i = 0; i < 5; i++) { for (int j = 0; j < 2; j++) { cout << “Element at arr[” << i << “][” << j << “]: “; cout << arr[i][j]<<endl; } } return 0; } int arr[5]={5,4,3,6,3}; int arr[500]; #include<iostream> using namespace std; int main() { int arr[1][3][2] = { { {0,1}, {2,3}, {4,5} } }; for (int i = 0; i < 1; ++i) { for (int j = 0; j < 3; ++j) { for (int k = 0; k < 2; ++k) { cout << “Element at arr[” << i << “][” << j << “][” << k << “] = ” << arr[i][j][k] << endl; } } } return 0; } #include<bits/stdc++.h> using namespace std; int main() { int a[][2] = {{1, 2}, {3, 4},{5,6}}; cout << sizeof(a); return 0; } #include<bits/stdc++.h> using namespace std; int main() { int a[][2] = {{1, 2}, {3, 4},{5,6}}; cout<<a; return 0; } #include<bits/stdc++.h> using namespace std; int main() { char str[7]=”DATA”; cout << str[2]<<” “<<str; return 0; } #include <iostream> using namespace std; int main() { // Initialize array of pointer const char *colours[5] = { “Green”, “Pink”, “Yellow”, “Orange” }; cout << colours[5]; return 0; } #include <iostream> #include <string> using namespace std; int main() { string student[4] = { “Harry”, “Ritik”, “Jaish”, “Jackline” }; for (int i = 0; i < 4; i++) if(i%2==0) cout << student[i] << ” “; return 0; } #include <iostream> #include <array> #include <string> using namespace std; int main() { array<string, 5> students {“Jaish”, “Gunjan”, “Vivaan”, “Harry” }; for (int i = 0; i < 4; i++) if(i%2!=0) cout << students[i] << ” “; return 0; } #include <iostream> using namespace std; int main() { int arr[5]; for (int i = 20; i > 15; i–) { *(arr + 20-i) = i – 1; } cout << “Values : “; for (int i = 0; i < 5; i++) { cout << *(arr + i) << ‘ ‘; } return 0; } Quiz Summary
Information
Results
Results
0 Essay(s) Pending (Possible Point(s): 0) Categories
1. Question
2. Question
3. Question
4. Question
5. Question
6. Question
7. Question
8. Question
9. Question
10. Question
11. Question
12. Question
13. Question
14. Question
15. Question
Summary
A programming language’s most essential concept is the array. Hope this quiz has helped you gauge your understanding of arrays. As you continue to attempt quizzes, you will learn more. Wishing you a wonderful learning experience!
What is the output of the following code?
#include
using namespace std;
int main()
{
int a[][2] = {{1, 2}, {3, 4},{5,6}};
cout << sizeof(a);
return 0;
}
3
24
rows = 3
columns = 2
3 * 2 = 6
int takes 4 bytes
therefore the size of ‘a’ is 6*4 = 24