On Fri, 18 Nov 2005 13:00:09 +0800, in comp.lang.c , nick
<i1********@yahoo.com> wrote:
#include <stdio.h>
#include <string.h>
int main(void)
{
char message[]="Welcome to C Programming!";
char *cptr;
cptr = message + 5;
printf("%c\n", cptr);
return 0;
}
the above code, when i put it in VC++.NET, it can't display properly.
but when i put it in MinGW Developer Studio, it can show the result 'm'.
why?
%c prints a character. The 5th character of message is 'm' which is
presumably what you were expecting.
However cptr is a pointer. Printing the pointer with %c is undefined
behaviour, and the result could be anything (often it will be the
value of the address, converted to a char). So, if you got 'm' on
Mingw, it was coincidence.
Change the printf to *cptr, to get the value stored at cptr.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----