Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: Pointer and string literal question

Reply
Thread Tools

Re: Pointer and string literal question

 
 
bartc
Guest
Posts: n/a
 
      12-10-2009

"Tagore" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pointer and string literal question Tagore C Programming 15 12-20-2009 01:17 PM
compare string and "" string literal lovecreatesbea...@gmail.com C++ 10 01-24-2007 09:55 PM
How to identify a pointer to a string literal weaselboy1976@gmail.com C Programming 12 01-09-2006 10:11 PM
What's wrong with rpc-literal? Why use doc-literal? Anonieko Ramos ASP .Net Web Services 0 09-27-2004 09:06 AM
String literal and String Object Prakash Prabhu Java 3 08-27-2003 09:18 PM



Advertisments