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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What happens if a header file is included twice?

823


What is the behavioral difference when include header file in double quotes (“”) and angular braces (<>)?

1090


What is time null in c?

785


Why enum is used in c?

723


What is the mean of function?

883


What is c programing language?

852


What is difference between class and structure?

859


What are the types of functions in c?

771


Explain how can I remove the trailing spaces from a string?

832


Explain modulus operator.

837


what is a NULL Pointer? Whether it is same as an uninitialized pointer?

1051


What is external variable in c?

835


How are structure passing and returning implemented?

804


Is c high or low level?

799


what is the c source code for the below output? 5555555555 4444 4444 333 333 22 22 1 1 22 22 333 333 4444 4444 5555555555

2810