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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Who invented turbo c++?

820


What problems might the following macro bring to the application?

774


What is the full name of logo?

802


How new/delete differs from malloc()/free?

817


If I is an integer variable, which is faster ++i or i++?

778






What do you mean by “this” pointer?

788


Can we use this pointer inside static member function?

806


Difference between a copy constructor and an assignment operator.

746


What is operators in c++?

763


You run a shell on unix system. How would you tell which shell are you running?

873


What is the auto keyword good for in c++?

836


Which operator cannot overload?

781


Does there exist any way to make the command line arguments available to other functions without passing them as arguments to the function?

964


Explain unexpected() function?

795


Why do you use the namespace feature?

849