[email protected] wrote:
> I worte my answers after the arrowes ==> . . .
> 
> --- In [ mailto:c-prog%40yahoogroups.com [EMAIL PROTECTED], Jim Dougherty
> <[EMAIL PROTECTED]> wrote:
>> No, a=b is NOT the same as *a=*b.
>>
>> Here are some examples that may help:
>>
>> int x; // ==>that's okay
>> int y; // ==>that's okay
>>
> 
>> int *a; // ==>that's also okay (defining pointers)
>> int *b; // ==>that's also okay (defining pointers)
> 
>> x = 123; // ==>that's okay too
>> y = 456; // ==>that's okay too
> 
>> a = NULL; // "A points at 0."
> // ==>that's like a = '\0' it's fine by me.
> // "*A is whatever int lies at 0."
> //==>did you mean that - 
> //==>*A points to a cell number(i.e. 1024) ?

I meant exactly what I said.
NULL is defined to be 0.
When you set your pointer A to NULL, A winds up pointing at address 0.
It does not point at 1024 or any other address, it points at address 0.
So *A is whatever INT happens to lie at address 0.
In practice you would never set A to NULL and then use *A because you have idea 
what data would happen to lie at address 0.
Pointers are often set to NULL as a way to indicate that they have not yet been 
initialized or set up.  If a pointer is NULL, it should not be used to access 
the data that it is pointing at.


>> a = x; // "illegal statement"
> //==> why it's illegal?

This is illegal because you are trying to assign X (which is an integer) to A 
(which is a pointer to an integer).  This does not make sense, A and X are 
different data types and the compiler should complain if you try to do this.


>> a = &x; // "A points at X. *A is 123 which is the value of X."
> //==>*A is what is INSIDE the cell(i.e. 123)
> //==>&A is the address of the cell(i.e. 1024)


>> b = &y; // "B points at Y. *B is 456 which is the value of Y."
> //==>that the same as *B=1024(as cell no.) ?

I do not understand what you are saying/asking.


>> a = b; //==> A now points at B which point at Y 
> //"*A is now 456."
> //==>and *A still points to Y ?

NO.  A and B are both pointers.  
We are setting A to point at the same thing that B points at.  
A now points at Y which is the same thing that B is pointing at.
*A is now 456 and *B is still 456.


>> *a = 789; //that's okay by me
> 
> ====== > > many thanks !!
>>
>>
>> [ mailto:c-prog%40yahoogroups.com [EMAIL PROTECTED] wrote:
>>> Hello again.
>>> and thanks for all the answers !!
>>>
>>> continuing from my question-
>>> is a=b the same like *a=*b ??
>>> *a == &a ? and *b==&b or I got it all mixed up?
>>> if a and b were initialized in the begining with NULL(\0),
>>> what was the difference ?
>>>
>>> --- In [ mailto:c-prog%40yahoogroups.com ][ mailto:c-prog%40yahoogroups.com
> [EMAIL PROTECTED], 
> Jim Dougherty
>>> <j_dougherty@> wrote:
>>>>
>>>> [ mailto:c-prog%40yahoogroups.com ][ mailto:c-prog%40yahoogroups.com
> [EMAIL PROTECTED] wrote:
>>>>> [ mailto:c-prog%40yahoogroups.com ][ mailto:c-prog%
> 40yahoogroups.com
>>> ][ mailto:c-prog%40yahoogroups.com [EMAIL PROTECTED] wrote:
>>>>>> defined -
>>>>>> int *a,*b;
>>>>>>
>>>>>> what's the difference between:
>>>>>>
>>>>>> 1. *a=b;
>>>>> Here, the location pointed to by A (which is an INT) 
>>>>> is set to the contents of pointer B (which is a pointer to an 
>>> INT).
>>>>> Note: the compiler should give you an error/warning about this.
>>>>>
>>>>>> 2. a=b;
>>>>> Here, the pointer A (which is a pointer to an INT) 
>>>>> is set to the contents of the pointer B (which is a pointer to 
> an 
>>> INT).
>>>> Maybe what you intended but did not specify was:
>>>>
>>>> *a = *b;
>>>>
>>>> Here, the location pointed to by A (which is an INT)
>>>> is set to the contents of the location pointed to by B (which is 
> an 
>>> INT).
>>>
>>>
>>>
>>>
>>>
>>>
>>>
> 
> 
> 
> 
>  
> 
> 



To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>. 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/c-prog/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/c-prog/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[EMAIL PROTECTED] 
    mailto:[EMAIL PROTECTED]

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

Reply via email to