Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


What is the difference between Char a[ ]=”string” and char
*a=”String”

Answers were Sorted based on User's Feedback



What is the difference between Char a[ ]=”string” and char *a=”String”..

Answer / prasant nayak

differences are as follows
1.
Char a[]="string"; //invalid, coz--its not 'Char' but
its 'char' , i.e its syntaticaly incorrect


char *a="string";//it correct

2.
char a[]="string";

above 'a' is an array of characters , where we can change
the string, its not a constant.
i.e we can do a[3] = 'Z';

char *a = "string";

above 'a' is a string constant where we can't change the
string i.e we can't do a[3] = 'Z';

Is This Answer Correct ?    42 Yes 6 No

What is the difference between Char a[ ]=”string” and char *a=”String”..

Answer / sushant mahajan

Ohk... dudes I think that 'C' in Char a[] is a typo. The only difference I can see is this:

char *a="string";
printf("%d", sizeof(a));
/*will print 2 or 4, whatever is the memory assigned to a pointer*/

char a[]="string";
printf("%d", sizeof(a));
/*will print 7 - 1 byte for each character+1 byte for the '\0' */

So basically its a memory thing :D

Is This Answer Correct ?    4 Yes 0 No

What is the difference between Char a[ ]=”string” and char *a=”String”..

Answer / kanakesh

using char*a we can't assign new individual character like
a[2]='k';

Is This Answer Correct ?    10 Yes 9 No

What is the difference between Char a[ ]=”string” and char *a=”String”..

Answer / vikram

char a[]="string" refers that string has constant length and it will reserve fixed memory while in case of char *a="string" the string has variable length

Is This Answer Correct ?    1 Yes 0 No

What is the difference between Char a[ ]=”string” and char *a=”String”..

Answer / thinker

Losers.! char* is not a constant pointer where as char[] is a constant pointer

Is This Answer Correct ?    2 Yes 1 No

What is the difference between Char a[ ]=”string” and char *a=”String”..

Answer / rajesh kumar

char *p="string" has RO permission while its counterpart char a[]="string" has RW permission.

Is This Answer Correct ?    0 Yes 0 No

What is the difference between Char a[ ]=”string” and char *a=”String”..

Answer / anshul

I guess the main difference for which interviewer was looking for it that name of the array is constant pointer and character pointer is not. So, if
char a1[]="string";
char *a2="string";

a2=a1;//Compiles and works perfectly
a1=a2;//Error caught at compile time

This is a famous example and is available in many C books.

Is This Answer Correct ?    0 Yes 0 No

What is the difference between Char a[ ]=”string” and char *a=”String”..

Answer / ratish

c/c++ is case sensitive language. so Char is invalid data type. hence char *a="String" is correct answer.

Is This Answer Correct ?    11 Yes 14 No

What is the difference between Char a[ ]=”string” and char *a=”String”..

Answer / vincy

the syntax for a character variable is wrong if we use a
pointer variable as given above that is char*a="string". so
i think the first one is right.we know that the pointer
variable points to the value in the particular address, then
it should not the "string" but "&string".

Is This Answer Correct ?    0 Yes 4 No

What is the difference between Char a[ ]=”string” and char *a=”String”..

Answer / niranjan kumar niraj

char a[]="string" returns characters and char *a[]="String"
returns address of character

Is This Answer Correct ?    1 Yes 7 No

Post New Answer

More C++ General Interview Questions

What are the various operations performed on stack?

0 Answers  


Any one help me plzzzz..... i have an assignment...... that is ______*********_______ Write a program that takes an equation as a string and does the following: Solve 8 parts to achieve 100% 1 - 5 are compulsory. Input: 2x^2+3x+4=0 1) read a quadratic equation 2) print its coefficients (coefficients range is 0 to 9) 3) print the solution of the equation 4) tackle imaginary solution e.g. ( (2+3i), (2-3i) ) 5) allow spaces within the input 6) after solving one equation; ask for an other, terminate on empty line. * 7) tackle negative values as well * 8) tackle more than one values of same exponent (e.g. 2x^2 + 3x^2 + 4x + 3 = 0)* 9) use strtok * 10) print the solution in fractions e.g. 1.5 should be printed as (1)1/2 * 11) coefficient can be greater than 9** 12) values on both sides of the ‘=’ sign** 13) plot the graph of the polynomial** 14) use a compiler other than Borland** 15) submit before May 25, 2009 11:59 PM ** _______******________ plz send me c++ code at sweety.alvi@gmail.com

1 Answers  


What is low level language in simple words?

0 Answers  


What is a dangling pointer in c++?

0 Answers  


How much is c++ certification?

0 Answers  


Explain how to initialize a const data member.

0 Answers  


What are built-in functions? What is the syntax for the definition?

0 Answers  


What is the use of "new" operator?

0 Answers  


Distinguish between a # include and #define.

0 Answers  


What is the size of integer variable?

0 Answers  


What is the best book for c++ beginners?

0 Answers  


Why are pointers not used in c++?

0 Answers  


Categories