What is the difference between char a[] = "string"; and
char *p = "string"; ?
Answers were Sorted based on User's Feedback
Answer / dharanidhar
P is a pointer which is constant. So, the values in this
array cannot be modified.
characters within a[] can be changed by accessing
like a[1] = '2',....
| Is This Answer Correct ? | 1 Yes | 3 No |
Answer / parmjeet kumar
char a[] will alocate the momery size of " string" word in
other hand char *p will alocate the memory size of one
character... or we can not move the data from one location
to another location but with pointer we can do it...
| Is This Answer Correct ? | 1 Yes | 5 No |
Answer / ashish
here a is an array and is a char const * data type.
hence u cannot change value of a but u can change the value
which a points to.
p on the other hand is a const char * data type.
hence value of p an be changed but the value p points to
cannot be changed.
i dont know the answer!!! :P
| Is This Answer Correct ? | 3 Yes | 13 No |
Answer / aravind
hi im answering as far as i know , pls say ur feedback,,,(+_+)
Array:
for char array char a[]; no such array size is accepted by
the compiler. That is , it requires a fixed size for the
array like: char a[20];
in this case the number of strings / characters it can hold
is only upto 20 while if it exceeds , the input strings get
truncated. [STATIC MEMORY ALLOCATION AND TRAVERSAL WITHIN
BOUNDS]
Pointer:
Whereas in case of pointers it is of DYNAMIC MEMORY type and
infinite storage when compared to Array. and predefinition ,
truncation are absent.
Also TRAVERSAL is easy.
| Is This Answer Correct ? | 6 Yes | 23 No |
second highest number in a given set of numbers
What is the output of the following program main();{printf ("chennai""superkings"}; a. Chennai b. superkings c. error d. Chennai superkings
What are the phases in s/w developed life cycle? wat is the diff b/w stack & queue...where do we use stack
Why are algorithms important in c program?
An interactive c program to read basic salary of 15 persons. each person gets 25% of basic as HRA, 15%of basic as conveyance allowances, 10%of basic as entertainment allowances.The total salary is calculated by adding basic+HRA+CA+EA.Calculate how many out of 15 get salary above 10,000.Rs also print the salary of each employee
How can I call system when parameters (filenames, etc.) Of the executed command arent known until run time?
A array contains dissimilar element how can we count, and A array contains dissimilar element how can we store in another array with out repetition.
the portion of a computer program within which the definition of the variable remains unchanged a) mode b) module c) scope d) none
int array[]={1,2,3,4,5,6,7,8}; #define SIZE (sizeof(array)/sizeof(int)) main() { if(-1<=SIZE) printf("1"); else printf("2"); }
What is else if ladder?
write a c program to find reminder and quotient if one number is divided by other.to code this program don't use more than 2 variables
What math functions are available for integers? For floating point?