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=&sum; } cout<<*ptr<<ptr; delete ptr; return 0; }

13th Feb 2017, 3:14 PM
vaibhav tomar
vaibhav tomar - avatar
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.
15th Feb 2017, 10:14 AM
Marcel Tuchner
Marcel Tuchner - avatar