You are given an array of integers which represents the ages of each employee in the office. Use operator sizeof() to get overal | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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; }

22nd Nov 2023, 9:48 PM
chukwudi anthony mbegbu
7 Answers
+ 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])
23rd Nov 2023, 3:42 PM
Jan
Jan - avatar
+ 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
23rd Nov 2023, 4:33 AM
BroFar
BroFar - avatar
+ 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);
23rd Nov 2023, 2:29 PM
BroFar
BroFar - avatar
+ 2
Quantum sizeof = 252 size = 63
23rd Nov 2023, 2:43 PM
BroFar
BroFar - avatar
+ 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
23rd Nov 2023, 11:38 AM
chukwudi anthony mbegbu
0
BroFar No, the task is to count the number of elements in the array.
23rd Nov 2023, 2:37 PM
Jan
Jan - avatar
0
Hi
24th Nov 2023, 10:00 AM
Gulam Murtaza Murtaza
Gulam Murtaza Murtaza - avatar