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
How do I read the arrow keys? What about function keys?
What is sizeof c?
Is c++ based on c?
Explain what is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?
Differentiate between the expression “++a” and “a++”?
how to create duplicate link list using C???
In cryptography, you could often break the algorithm if you know what was the original (plain) text that was encoded into the current ciphertext. This is called the plain text attack. In this simple problem, we illustrate the plain text attack on a simple substitution cipher encryption, where you know each letter has been substituted with a different letter from the alphabet but you don’t know what that letter is. You are given the cipherText as the input string to the function getwordSets(). You know that a plain text "AMMUNITION" occurs somewhere in this cipher text. Now, you have to find out which sets of characters corresponds to the encrypted form of the "AMMUNITION". You can assume that the encryption follows simple substitution only. [Hint: You could use the pattern in the "AMMUNITION" like MM occurring twice together to identify this]
What are the different data types in C?
What is the meaning of 2d in c?
What is the main difference between calloc () and malloc ()?
What is c language & why it is used?
How many main () function we can have in a project?
What math functions are available for integers? For floating point?
What is c language and why we use it?
write a program to concatenation the string using switch case?