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...

Recommended Answers

All 4 Replies

const means constant.

that it won't be changed anywhere within the scope where it is implemented.

if a function takes, for example, a pointer to a "const char" argument, you know you can pass in a string to that argument and your string will not be modified by the function.

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[1] 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" );
  return 0;
}

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..

commented: wrong -1

no. const and define are not the same thing.

do not attempt to re-answer threads that were already completely answered two days ago, especially if your answer is wrong.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.