+ 3
Please help in this code
8 Réponses
+ 3
thank u
dhanyabaad
+ 2
in prototype and in definition I use arr
in main I use ar I think there is no issue
+ 2
if don't use cout sum then it doesn't display anything why?
+ 2
thank u so much
but I. am not able to understand pointer concept
please use simple language I am beginner
+ 1
#include <iostream>
using namespace std;
int sum(int arr[], int);
int main()
{
int p=5;
int ar[5]={3,5,4,6,7};
cout<<sum(ar, p);
return 0;
}
int sum(int arr[], int)
{
int total=0;
for(int i=0;i<5;i++)
{total+=arr[i];}
return total;
}
+ 1
cout is the std stream function which says the compiler to print this statement..
but there was two problem in this code :
u were trying to convert the int p as a pointer to the array.. sum(a[p],p)
the second problem was you didn't had any print statement in it.. so I added cout<<
+ 1
for pointer.. it is a vast topic to understand.. u will learn further ..
but for pointer in short and simple... pointers are the variable created to store the address of a local variable or of a pointer..
kisi b variable ya pointer Ka address store krta h pointer
0
What's the name of your array: "ar" or "arr"?