Re: Pointer and string literal question

Discussion in 'C Programming' started by bartc, Dec 10, 2009.

  1. bartc

    bartc Guest

    "Tagore" <> wrote in message
    news:...
    > hi,
    >
    > #include <stdio.h>
    > int main(void){
    > char *s="LET";
    > char *t="LET";
    > if(s==t)
    > printf("same");
    > else
    > printf("different");
    > return 0;
    > }
    >
    > In above code, output is "same".
    > but I expected output to be "different". I think that s and t points
    > to string literals present at different addresses.
    > Can any one please help me in understanding its output.


    Because the literals are identical, perhaps only a single copy is used.

    --
    Bartc
    bartc, Dec 10, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Prakash Prabhu

    String literal and String Object

    Prakash Prabhu, Aug 27, 2003, in forum: Java
    Replies:
    3
    Views:
    635
    John C. Bollinger
    Aug 27, 2003
  2. Replies:
    12
    Views:
    426
    Kenny McCormack
    Jan 9, 2006
  3. Replies:
    10
    Views:
    771
    Roland Pibinger
    Jan 24, 2007
  4. Tagore

    Pointer and string literal question

    Tagore, Dec 10, 2009, in forum: C Programming
    Replies:
    15
    Views:
    657
    Ben Bacarisse
    Dec 20, 2009
  5. Anonieko Ramos

    What's wrong with rpc-literal? Why use doc-literal?

    Anonieko Ramos, Sep 27, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    374
    Anonieko Ramos
    Sep 27, 2004
Loading...

Share This Page