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

How the keyword struct is different from the keyword class in c++?

816


What is array in c++ example?

868


Difference between a copy constructor and an assignment operator.

791


Define the operators that can be used with a pointer.

827


How would you find out if a linked-list is a cycle or not?

775


Assume studentNames and studentIDs are two parallel arrays of size N that hold student data. Write a pseudocode algorithm that sorts studentIDs array in ascending ID number order such that the two arrays remain parallel.

1992


What is the v-ptr?

938


Why do we use the using declaration?

947


Refer to a name of class or function that is defined within a namespace?

866


Why are pointers used?

769


What is meant by const_cast?

885


List the issue that the auto_ptr object handles?

829


What are member functions used in c++?

814


What is low level language in simple words?

827


What is runtime polymorphism in c++?

858