differentiate between
const char *a;
char *const a; and
char const *a;

Answers were Sorted based on User's Feedback



differentiate between const char *a; char *const a; and char const *a; ..

Answer / vignesh1988i

const char *a : means the string is constant and the pointer
is not...

const char *a="HELLO WORLD" , if we take this example for
the whole scope of the program the string is constant and we
can't assign any other string to that pointer 'a'....

char * const a : means the pointer is constant (address) but
string is not......

char * const a="hello world" , if we take this example ,
here the address will be always constant.... string can vary..

char const *a : means string is a constant and pointer is
not..... as we have seen from the first example...


thank u

Is This Answer Correct ?    37 Yes 2 No

differentiate between const char *a; char *const a; and char const *a; ..

Answer / shaista naaz

char * a = "Hello world";
1)
we cannot make a[i] = 'Some character'. This is not allowed.
but we can make
a = "Hi world";
that is char * a is basically a is a pointer which can point
to different address like when we say
a = "Hello world" and then we say a = "Hi world";
Here a is pointing to different address bit as I said before
If we try a[i] = 'some char' will give compiler error as
because here the string is constant not pointer so this is
const char * a = a is a pointer which is pointing to a
constant string. This is a default behaviour.
2)
char * const a = "I am good" ;
Now here you cannot do any thing no modification allowed.
Try doing a[0] = 'Y';
it fails.
Try doing a = "You are good";
It fails too
Error is You cannot assign to a variable which is a constant.
So a is a variable which is a pointer to character and is
constant.
or a is a constant pointer to character.
3)
char const * a = const char *a
As in both the case a is a pointer to character which is
constant and a can point to different string but this string
itself cannot be modified. This is the default behavior of
char * a.

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More C Interview Questions

what is meant by c

9 Answers   INiTS,


main() { int a[10]; printf("%d",*a+1-*a+3); }

2 Answers  


Given an array A[n+m] of n+m numbers, where A[1] ... A[n] is sorted and A[n+1] ... A[n+m] is sorted. Design a linear time algorithm to obtain A[1...n+m] sorted using only O(1) extra space. Time Complexity of your algorithm should be O(n) and Space Complexity O(1).

0 Answers  


c pgm count no of lines , blanks, tabs in a para(File concept)

2 Answers  


Why void main is used in c?

0 Answers  






What are formal parameters?

0 Answers  


How can I remove the leading spaces from a string?

0 Answers  


In how much time you will write this c program? Prime nos from 1 to 1000

2 Answers   TCS,


program for comparing 2 strings without strcmp()

4 Answers  


I was asked to write a program in c which when executed displays how many no.of clients are connected to the server.

0 Answers  


What happens if header file is included twice?

0 Answers  


. Write a program to get a string and to convert the 1st letter of it to uppercase

2 Answers   HTC,


Categories