Welcome, %1$s. Please login or register.

December 14, 2017, 10:30:59 PM
: 1
: String declarations!  ( 2652 )
« : June 09, 2007, 01:29:31 PM From Poonam»



String declarations!


What are the differences between the following 2 declarations?

char *string1 = "Hello World";
char string2[] = "Hello World";

 
Liked It? Share it!

              


« #1 : June 10, 2007, 02:00:21 PM From satyadb4u»

string1 is a pointer pointing towards location of constant string literal "hello world"

where as string2 is the base of the string array "hello world"

i.e sizeof(string1) is 4 where as sizeof the string2 is sizef of string...

u cant modify string2 where as you can make string1 point to any other location...
« #2 : August 09, 2007, 01:33:31 PM From eisenham»

U can change the contents of string2 while u can make string1 to point to other string but cannot modify contents of string1.
This is becoz string1 is pointer to constant string. Modifications to contents of string2 are possible.
« #3 : August 09, 2007, 01:35:44 PM From Poonam»

Hey nice replies.. didn't know that there were so many differences. [:)]. Thanks.
« #4 : September 01, 2008, 12:34:59 PM From satyadb4u»

Right back after long time :D
: 1
« previous next »

 

Best RatedList All>>



Latest
Random



SMF 2.0.10 | SMF © 2015, Simple Machines | Contact Webmaster | OnlineFunDb.com © 2009/10 | Legal Disclaimer