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

What methods can be overridden in java?

940


Explain the auto storage classes in c++.

835


What does the ios::ate argument do?

913


What is the basic concept of c++?

759


How do you clear a buffer in c++?

733


What is a multiset c++?

784


Is map thread safe c++?

860


By using c++ with an example describe linked list?

805


Differentiate between a pointer and a reference with respect to c++.

956


What is a c++ vector?

789


Explain public, protected, private in c++?

764


Which recursive sorting technique always makes recursive calls to sort subarrays that are about half size of the original array?

811


Describe public access specifiers?

808


How should runtime errors be handled in c++?

851


Is oops and c++ same?

789