What is the difference between char a[] = "string"; and
char *p = "string"; ?

Answers were Sorted based on User's Feedback



What is the difference between char a[] = "string"; and char *p = "string"; ?..

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

What is the difference between char a[] = "string"; and char *p = "string"; ?..

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

What is the difference between char a[] = "string"; and char *p = "string"; ?..

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

What is the difference between char a[] = "string"; and char *p = "string"; ?..

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

Post New Answer

More C Interview Questions

Write a routine that prints out a 2-D array in spiral order!

1 Answers   Lucent,


Device an algorithm for weiler-atherton polygon clipping, where the clipping window can be any specified polygon

0 Answers  


Given a number N, product(N) is the product of the digits of N. We can then form a sequence N, product(N), product(product(N))… For example, using 99, we get the sequence 99, 99 = 81, 81 = 8. Input Format: A single integer N Output Format: A single integer which is the number of steps after which a single digit number occurs in the sequence. Sample Test Cases: Input #00: 99 Output #00: 2 Explanation: Step - 1 : 9 * 9 = 81 Step - 2 : 8 * 1 = 8 There are 2 steps to get to this single digit number. Input #01: 1137638147

2 Answers  


we have to use realloc only after malloc or calloc ? or we can use initially with out depending on whether we are using malloc or calloc in our program ?

2 Answers  


can we declare a variable in different scopes with different data types? answer in detail

3 Answers   TCS,






How do you define a function?

0 Answers  


What is a 'null pointer assignment' error?

0 Answers  


A woman had somany gloves and hats 22 red,34 blue, 45 white...there was power cut and she took a glove and how many gloves shud she take so that she gets a pair of glove fr each color??

3 Answers   TCS,


how to make c program without a libary? e.g.#include<stdio.h> libary is not in c progaram.

2 Answers  


Which is best linux os?

0 Answers  


diff. between *p and **p

3 Answers  


how to swap 2 numbers within a single statement?

4 Answers  


Categories