why?!

why dose this progrem gives me garbage?

#include<iostream>
#include<stdio.h>
using namespace std;
int nuf(int *x){

int sum1;
int sum2 = 0;
while(*x != NULL){
sum1 = *x;
sum2 += sum1;
x++;
}

return sum2;


}
main(){
int num[] = {1,2,3};
int y;
y = nuf(&num[0]);
cout << y;
return 0;

}
Line 8: Where do you think a NULL is stored? There is no NULL in your initialization list at line 19. C++ does not automatically provide a NULL at the end of your list. You're going to index through random memory until your program crashes or you find a random word containing 0.

Line 18: main must be declared to return an int.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/


thank u
Topic archived. No new replies allowed.