![]() |
Why pointer cant have only value?
This is very simple question!!! Give me excat reason???
Example: Why it is wrong.... int main() { int * ptr; *ptr=10; return 0; } |
Re: Why pointer cant have only value?
First you submitted your query as article and I have moved to the forum for discussion and next thing is your query and I don't see anything wrong there?
|
Re: Why pointer cant have only value?
It's wrong because you did this
*ptr = 10; before you did this ptr = somewhere; You can't just declare a pointer and magically hope it points to somewhere useful. You have to do it yourself. Chaos and madness result if you don't. int a; ptr = &a; Gets you a pointer to ONE integer int a[10]; ptr = a; Gets you a pointer to TEN integers ptr = malloc( sizeof(*ptr) * 10 ); This too is a pointer to 10 integers. But at some point, you need to do free( ptr ); |
Re: Why pointer cant have only value?
That's fine . I did'nt mean that.
Fetaures should be as ... 1. Pointer keeping Only Address 2. Pointer Keeping Only Values 3. Both 1 & 2 approximately same. But why 2 is not supported?? |
Re: Why pointer cant have only value?
dont tell me story of pointer that Pointer is made for only keeping some address . This is known by all.
|
Re: Why pointer cant have only value?
Quote:
|
Re: Why pointer cant have only value?
In that case, I've no idea what your question is.
|
Re: Why pointer cant have only value?
friend if pointer will only have values then what do you want to do with the variables !!
Code:
int var;if pointer will only have values then what is the use of pointers... |
Re: Why pointer cant have only value?
Quote:
I wanna use like this manner.... Code:
int main() |
Re: Why pointer cant have only value?
Sure, there's no problem with reassigning the pointer to point somewhere else, with p = &x;
The real problem with your code is that at *p = 10, your pointer is UNINITIALISED. That means the code is broken. Try Code:
int *p; |
| All times are GMT +5.5. The time now is 03:23. |