In the linked lists tutorial, it says pointers are equal to values without a & before them. Does the compiler like this idea or why doesn't it give errors?
In the linked lists tutorial, it says pointers are equal to values without a & before them. Does the compiler like this idea or why doesn't it give errors?
Child who knows C++Using Borland C/C++ Compiler 5.5 (Command Line Version)
It wouldn't give errors, because you can set a variable to whatever you like. The compiler doesn't understand the logic behind your program, just the syntax. It's like Microsoft Word won't tell you if you have a run-on sentence (well it never used to... it's getting pretty smart), because it doesn't understand what you're talking about, it only understand sentence structure and a dictionary. You can set pointers to anything you like, it's just that the idea of a pointer is based on assigning it a memory address. If you have a purpose for a pointer that doesn't need it to be a &'ed value, the compiler's fine with that - they're not that different from ordinary variables. Memory addresses are just numbers anyway!
(of course, I haven't read that tutorial so the problem may just be that you're not understanding the -> operator, which will dereference for you - but hopefully this helps)
conductor is a pointer and next is a pointer. I understand how a pointer could point to a pointer but it would need to have a & before it! Huh?Originally Posted by Cprogramming Tutorial
Child who knows C++Using Borland C/C++ Compiler 5.5 (Command Line Version)
no, & means "address of", since next already holds the address of something there is no need for the & there. Using & there would give you the address of next and not what next is pointing to.
Next is pointing to NULL there though???????!?!??!?!?!?!?
Child who knows C++Using Borland C/C++ Compiler 5.5 (Command Line Version)
Am I ASCIIng a stupid question and getting a stupid ANSI, Salem?
Child who knows C++Using Borland C/C++ Compiler 5.5 (Command Line Version)
There is nothing wrong with it pointing to NULL. Now if you tried to dereference it after that then you would have a problem.