Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

what's the meaning of "sum += num[i]"?

+3 votes
asked Jul 17, 2018 by Tylen Okundi (260 points)

What's the meaning of sum +=num[] in c++ arrays?(especially for an array like num[])?

6 Answers

0 votes
answered Jul 20, 2018 by KAUSTAV (720 points)

sum += num[] means sum = sum + num[]

or simply, sum[0] = sum[0] + num[0]

0 votes
answered Jul 21, 2018 by Priyansh (250 points)
Hey,

sum+=num[] means sum=sum+num[];
0 votes
answered Jul 21, 2018 by Akhila Mekapothula (460 points)
#include<stdio.h>

main()

{

int I,n,sum=0,num[20];

printf("enter no.of numgers\n");

scanf("%d",&n);

for(I=0;i<n;i++)

{

sum=sum+num[I];

}

printf("sum=%d\t",sum);

}
0 votes
answered Jul 27, 2018 by Devendra Saini (140 points)

sum += num[ ]means sum = sum + num[ ]

0 votes
answered Jul 28, 2018 by sriraam (140 points)

its called as array index.

syntax:

data type  var name[size]

int a[3]

its used to allocate the memory for the variables.

          0                                           1                                                  2

         100                                        102                                    104

these(0,1,2)is your memory and (100,102,104)is your memory address.

note:

Array index starts with the value 0 and ends with the value n-1 which n is the size. 

0 votes
answered Jul 30, 2018 by Sujit Gupta (140 points)
i+=1;

Means i=i+1; there fore sum=sum+num[i]; means

Suppose value of num[i]=1 and sum=5;

Therefore sum=sum+num[i];

                   Sum= 5 + 1;

And now 6 is stored in sum :::: answer-- sum=6

num[i] is 1 dimensional array.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...