Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Safe Array Access | Working with Array Elements
C++ Arrays

bookChallenge: Safe Array Access

Opgave

Swipe to start coding

Write a function sumArray that takes a constant integer array and its size as parameters and returns the sum of all elements in the array.

  • Access only valid indices in the array (from 0 to size - 1);
  • Do not use any global variables or additional libraries;
  • Declare and initialize the array in main, then pass it with its size to sumArray;
  • Return the total sum from the function.

Løsning

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 2. Kapitel 3
single

single

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

close

bookChallenge: Safe Array Access

Stryg for at vise menuen

Opgave

Swipe to start coding

Write a function sumArray that takes a constant integer array and its size as parameters and returns the sum of all elements in the array.

  • Access only valid indices in the array (from 0 to size - 1);
  • Do not use any global variables or additional libraries;
  • Declare and initialize the array in main, then pass it with its size to sumArray;
  • Return the total sum from the function.

Løsning

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 2. Kapitel 3
single

single

some-alt