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
what are the program that using a two dimensional array that list the odd numbers and even numbers separately in a given 10 inputs values
Differentiate between new and malloc(), delete and free() ?
The % symbol has a special use in a printf statement. Explain how would you place this character as part of the output on the screen?
Explain how do you sort filenames in a directory?
What do you mean by dynamic memory allocation in c?
Sir,please help me out with the code of this question. Write an interactive C program that will encode or decode multiple lines of text. Store the encoded text within a data file, so that it can be retrieved and decoded at any time. The program should include the following features: (a) Enter text from the keyboard, encode the text and store the encoded text in a data file. (b) Retrieve the encoded text and display it in its encoded form. (c) Retrieve the encoded text, decode it and then display the decoded text. (d) End the computation. Test the program using several lines of text of your choice.
What is the 'named constructor idiom'?
What do you mean by a sequential access file?
What is difference between main and void main?
What is the use of void pointer and null pointer in c language?
What are valid signatures for the Main function?
What is a spanning Tree?
Explain the properties of union.
Between macros and functions,which is better to use and why?
which of the following is not a character constant a) 'thank you' b) 'enter values of p, n ,r' c) '23.56E-o3' d) all of the above