const is a qualifier for objects that tells the compiler you won't try to modify the object's value:
int x = 10;
const int y = 10;
x = 20; /* Okay */
y = 20; /* Bzzt! y is const */
const is short for constant, which really means read-only rather than truly constant. It's typically used for pointer parameters that shouldn't be modified:
void print_chars ( const char *s )
while ( *s != '\0' )
putchar ( *s++ );
int main ( void )
print_chars ( "This is a test" );
In the above code, a string literal is passed to print_chars. String literals reside in read-only memory, which means trying to modify them could potentially cause a runtime error. print_chars doesn't need to modify the string passed, so it specifies the parameter as const to tell callers that it's safe to pass string literals.
I want to know what is const type in C and what is its uses etc.
i dont know anything about this term used in C so please give detailed description...
const is a keyword in c language.
if we are using const before any variable and assigning some value to it then it cannot be changed in that program.
const int x=10;
if you are declaring this then the value of x cannot be modified.
we also can use
#define x 10
for the same property it will also work.
it is a macro .
god bless you happy learning..