0
You are given an array of integers which represents the ages of each employee in the office. Use operator sizeof() to get overal
Use operator sizeof() to get the overall size of memory allocated by the array and the size of one element in that array. #include <iostream> using namespace std; int main() { int ages[] = {19, 24, 36, 45, 56, 52, 21, 27, 24, 34, 29, 60, 40, 42, 45, 47, 22, 30, 34, 20, 18, 26, 51, 43, 47, 39, 22, 34, 56, 52, 21, 27, 24, 37, 19, 24, 36, 45, 44, 49, 23, 25, 19, 40, 29, 60, 40, 42, 45, 47, 61, 30, 19, 43, 47, 39, 41, 46, 29, 24, 21, 25, 28}; //your code goes here cin>>ages[]; cout << "ages:" << sizeof(ages) << endl; return 0; }
7 Réponses
+ 2
BroFar When I made that task, I used this piece of code to get the number of elements, and that's all for that task.
sizeof(ages) / sizeof(ages[0])
+ 3
chukwudi anthony mbegbu are you asking a question? I see at least one error right off ...
What is the purpose of
cin >> ages[];
ages is already initialized as an array
+ 2
chukwudi anthony mbegbu the code coach is Average Age meaning they want you to cycle through the array ...
So first is not sizeof but size...
int s = size(ages);
+ 2
Quantum
sizeof = 252
size = 63
+ 1
Sorry, this is how the practice code is #include <iostream>
using namespace std;
int main() {
int ages[] = {19, 24, 36, 45, 56, 52, 21, 27, 24, 34, 29, 60, 40, 42, 45, 47, 22, 30, 34, 20, 18, 26, 51, 43, 47, 39, 22, 34, 56, 52, 21, 27, 24, 37, 19, 24, 36, 45, 44, 49, 23, 25, 19, 40, 29, 60, 40, 42, 45, 47, 61, 30, 19, 43, 47, 39, 41, 46, 29, 24, 21, 25, 28};
//your code goes here
return 0;
}
Please complete for me
0
BroFar No, the task is to count the number of elements in the array.
0
Hi