This is very simple question!!! Give me excat reason???
Example: Why it is wrong....
int main()
{
int * ptr;
*ptr=10;
return 0;
}
|
Go4Expert Founder
|
![]() |
| 11Jan2008,19:22 | #2 |
|
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?
|
|
Ambitious contributor
|
|
| 11Jan2008,19:31 | #3 |
|
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 ); |
|
TechCake
|
|
| 11Jan2008,20:09 | #4 |
|
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?? |
|
TechCake
|
|
| 11Jan2008,20:14 | #5 |
|
dont tell me story of pointer that Pointer is made for only keeping some address . This is known by all.
|
|
Go4Expert Founder
|
![]() |
| 11Jan2008,21:05 | #6 |
|
Quote:
Originally Posted by asadullah.ansari |
|
Ambitious contributor
|
|
| 12Jan2008,14:29 | #7 |
|
In that case, I've no idea what your question is.
|
|
Contributor
|
|
| 14Jan2008,15:41 | #8 |
|
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... |
|
TechCake
|
|
| 16Jan2008,12:19 | #9 |
|
Quote:
Originally Posted by technosavvy I wanna use like this manner.... Code:
int main()
{
int *p,x=23;
*p=10;
//Some operation like simple variables
......
......
printf("%d", *p);
//After some Instant
p=&x;
// Some operation like pointer features As popular)
......
......
printf("%d", *p);
return 0;
}
|
|
Ambitious contributor
|
|
| 16Jan2008,13:28 | #10 |
|
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; int old, new; p = &old; *p = 10; ... p = &new; *p = 20; |

