True or false - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

True or false

Panasonic99Panasonic99 Posts: 140Member
1. Two pointers that point to different arrays cannot be compared meaningfully.
2. Because the name of an array is a pointer to the first element of the array, array names may be manipulated in precisely the same manner as pointers.

I'd say the first one is true and the second one is false......?

Comments

  • DonotaloDonotalo Posts: 715Member
    [b][red]This message was edited by Donotalo at 2005-8-6 19:59:0[/red][/b][hr]
    : 1. Two pointers that point to different arrays cannot be compared meaningfully.
    [purple]Not clear. What kind of comparison?[/purple]

    : 2. Because the name of an array is a pointer to the first element of the array, array names may be manipulated in precisely the same manner as pointers.
    [purple]ya, u cant [red]precisely[/red] use an array name as a pointer. u can treat the array name as a pointer. however, u cant change the value of that pointer, i.e., assign a new address to that pointer or pointer increment/decrement.[/purple]
  • stoberstober Posts: 9,765Member ✭✭✭
    : : 1. Two pointers that point to different arrays cannot be compared meaningfully.

    assume ptr1 = "James" and ptr2 = "Jones". Now use strcmp() to see if the two values are the same. So the answer to the this question is false because they can be compared.
  • AsmGuru62AsmGuru62 Posts: 6,519Member
    : : : 1. Two pointers that point to different arrays cannot be compared meaningfully.
    :
    : assume ptr1 = "James" and ptr2 = "Jones". Now use strcmp() to see if the two values are the same. So the answer to the this question is false because they can be compared.
    :
    [blue][b]stober[/b], two [red]pointers[/red] - not the two [red]contents[/red] of these pointers, so in my opinion - the answer is true.[/blue]
  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member
    [b][red]This message was edited by BitByBit_Thor at 2005-8-7 13:21:35[/red][/b][hr]
    : : : : 1. Two pointers that point to different arrays cannot be compared meaningfully.
    : :
    : : assume ptr1 = "James" and ptr2 = "Jones". Now use strcmp() to see if the two values are the same. So the answer to the this question is false because they can be compared.
    : :
    : [blue][b]stober[/b], two [red]pointers[/red] - not the two [red]contents[/red] of these pointers, so in my opinion - the answer is true.[/blue]
    :

    1. The answer is "True" when you assume they point to different arrays.
    If you leave that part out, than the meaning of checking it would be to see if they point to the same address.

    2. Actually... the other way around is True: you can handle pointers as if they were an array.

    Greets...
    Richard
  • stoberstober Posts: 9,765Member ✭✭✭
    : : : : : 1. Two pointers that point to different arrays cannot be compared meaningfully.
    : : :
    : : : assume ptr1 = "James" and ptr2 = "Jones". Now use strcmp() to see if the two values are the same. So the answer to the this question is false because they can be compared.
    : : :
    : : [blue][b]stober[/b], two [red]pointers[/red] - not the two [red]contents[/red] of these pointers, so in my opinion - the answer is true.[/blue]
    : :
    :
    : 1. The answer is "True" when you assume they point to different arrays.
    : If you leave that part out, than the meaning of checking it would be to see if they point to the same address.
    :


    I would still consider question 1 FALSE because you can make a meaningful comparison of two addresses -- to check if both pointers point to the same object.

  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member

    : I would still consider question 1 FALSE because you can make a meaningful comparison of two addresses -- to check if both pointers point to the same object.
    :
    :

    But in the question it is already stated that they DO NOT point to the same array (or object). *lol*

    Greets...
    Richard

Sign In or Register to comment.