I have tried many tutorials and got more confused. So please teach this noob with simplest answers. If possible then just stick to the question......i am having information overload :)
first the main function
main(){
int y=0;
display(&y);
}
Now the function
int display(int* x){
//do something depending on different values of x
}
One of the case is following: "if no variable is pointed to, that is, if the address of the variable is NULL, your function sets the value of the variable pointed to zero."
Now my understanding in display function i need to do
if (x==NULL)
*x=0;
Now here is where I am getting stuck with...... - if i call the function with display(NULL); I get following error in Visual "Unhandled exception at 0x00C84036 in BTP 300 A1.exe: 0xC0000005: Access violation writing location 0x00000000."
How do i store some value in y from a function if its address is null?
or the question is just wrong and it should have said value stored at the address, to which pointer variable points, is null i.e y=Null ???
If int* z is a null pointer than what is the value of the address to which z points to and what is the value that is stored in address that is pointed???
displaya given? What does the return value mean? Maybe they meandisplayshould return 0 ifNULLis passed in? Either way, it's something that needs to be clarified by the teacher, not by SO. If they don't, press harder. There's lots of crummy teachers around.