what is the difference between char * const and const char
*?

Answers were Sorted based on User's Feedback



what is the difference between char * const and const char *?..

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

what is the difference between char * const and const char *?..

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

Post New Answer

More C Interview Questions

wat is the difference between array and pointer?

4 Answers   Wipro,


how can f be used for both float and double arguments in printf? Are not they different types?

0 Answers  


A collection of data with a given structure for excepting storing and providing on demand data for multiple users a) linked list b) datastructer c) database d) preprocessor

0 Answers  


Explain what is the benefit of using enum to declare a constant?

0 Answers  


logic for x=y^n

1 Answers   Delphi,






the 'sizeof' operator reported a larger size than the calculated size for a structure type. What could be the reason?

0 Answers  


can anyone please tell about the nested interrupts?

0 Answers  


What are structure types in C?

0 Answers  


What would the following code segment printint k = 8;docout << "k = " << k << " ";while k++ < 5; a) 13 b) 5 c) 8 d) pointers

0 Answers  


I came across some code that puts a (void) cast before each call to printf. Why?

0 Answers  


Hi Every one......... Please Any body give me the answer for my question. Is it possible to print the word "PRINT F", without using printf() statement in C-Language.

4 Answers  


how to find a 5th bit is set in c program

4 Answers   IBM,


Categories