0
Kindly make debug the following code
#include <iostream> using namespace std; int main() { int x[10],int *ptr=new int; int sum=0; for(int i=0; i<=10;i++) {sum= sum +x[i]; ptr=∑ } cout<<*ptr<<ptr; delete ptr; return 0; }
1 Odpowiedź
0
Your Integer Array is either Filled with zeroes or with Null (check that pls!)also you dont have to assign the Pointer to the sum value. you can print sum in std::cout -> std::cout << sum << std::endl. So I would erase the Pointer there it is not necessary. Also if you are not dereferencing your Pointer with "*" you will just get the Pointer Location and not the Value of sum.