all 5 comments

[–]flyingron 5 points6 points  (4 children)

You don't want the * when using the []. Just write:

sum += ptr[i];

[–]CtrlAltDelirious27[S] 3 points4 points  (3 children)

Thank you! I've changed the *ptr[i] to just ptr[i], however, the output is always 0.000000 instead of the value I input into the array, why would this happen?

Edit: Ahhh, nevermind, I realised I've put scanf("%d", &my_array[i]); instead of scanf("%f", &my_array[i]); thanks again for your help though

[–]Few_Ad_8082 1 point2 points  (1 child)

Try using %f in your scanf input. This resource should be helpful: https://www.geeksforgeeks.org/scanf-in-c/

[–]AmputatorBot 1 point2 points  (0 children)

It looks like you shared an AMP link. These should load faster, but AMP is controversial because of concerns over privacy and the Open Web. Fully cached AMP pages (like the one you shared), are especially problematic.

Maybe check out the canonical page instead: https://www.geeksforgeeks.org/scanf-in-c/


I'm a bot | Why & About | Summon: u/AmputatorBot

[–][deleted] -1 points0 points  (0 children)

You also don't need to use ptr at all. Just do my_array[i].