what is the difference between char * const and const char
*?
Answers were Sorted based on User's Feedback
Answer / brindha
Char* const p -> Here pointer P is a const pointer, which
means that this pointer can point to only one memory
location. eg. char* const p = &arr;
p++ ; -> This is invalid
const char* p -> this indicates that the data pointed by
the pointer p is constant & the value in that address
cannot be modified. eg. const char* p = 'a';
*p = 'b'; -> This is invalid
| Is This Answer Correct ? | 30 Yes | 2 No |
Answer / yathish nm yadav
CHAR * CONST
means we are making the variable of type
char* as constant i.e,
ex:
char * const p;
means pointer variable p is made constant i.e, its lvalue
is been blocked by compiler at compile time.
ex:
char c;
char *const p= &c;
here p contains the adress of c and we cannot make p now to
point to some other variable.
char t;
p=t; //compile time error.
CONST CHAR *
means the variable pointed to by the const char * is made
constant. i,e.
ex:
char c='a';
const char *p=&c;
here c is made constant n its lvalue is being blocked.
now we cannot change the value of c since it is made
constant.
i.e,
*p='b'; // error
| Is This Answer Correct ? | 2 Yes | 0 No |
What are the characteristics of arrays in c?
Write an algorithm for a program that receives an integer as input and outputs the product of of its digits. E.g. 1234 = 24, 705 = 0
what is the code to display color fonts in the output?
Write a simple code fragment that will check if a number is positive or negative.
Explain what does a function declared as pascal do differently?
How can I read/write structures from/to data files?
What will be the output of x++ + ++x?
what is the disadvantage of using macros?
Write a program to identify if a given binary tree is balanced or not.
write the program for maximum of the following numbers? 122,198,290,71,143,325,98
5 Write an Algorithm to find the maximum and minimum items in a set of ‘n’ element.
What is identifiers in c with examples?