what is the difference between
const char *p, char const *p, const char* const p

Answers were Sorted based on User's Feedback



what is the difference between const char *p, char const *p, const char* const p ..

Answer / kumar krishna

CONST char *p;
here the const. keyword is coming before the "*p"
So it affects the value pointed by "p" i.e. "*p"
You can't change the character (value pointed by p).
Although you can change the address stored in "p".

char CONST *p;
same explanation as above

char * CONST p;
here the const. keyword is coming before the "p" and
after "*" So it affects the value of "p" (which holds
the address). You can't change the address stored in
"p". Although you can change the value pointed by p
i.e. "*p"

CONST char* CONST p:
here CONST is coming before the "*" as well as after
the "*". Therefore, as expeected neither the address
of nor the value pointed by "p" can be changed.

Is This Answer Correct ?    170 Yes 11 No

what is the difference between const char *p, char const *p, const char* const p ..

Answer / singamsa

const char*p - p is pointer to the constant character i.e
value in that address location is constact

char const *p - same as above

const char* const p - p is the constant pointer which
points to the constant string, both value and address are
constants

Is This Answer Correct ?    115 Yes 49 No

what is the difference between const char *p, char const *p, const char* const p ..

Answer / vignesh1988i

CONST char *p:
here the const. keyword is coming before the data
type... so the string here will be the constant but not he
pointer...
char CONST *p:
here also the string will be the constant but not the
pointer...
CONST char* CONST p:
here both , the string as well the pointer will be constant

Is This Answer Correct ?    64 Yes 32 No

what is the difference between const char *p, char const *p, const char* const p ..

Answer / magdaleen

In a const char *p the chrac pointed by 'p' is a const, so
u cant change the value of the charac ponted by 'p', but u
can make 'p' refer to some other location.

In a char const *p, the ptr 'p' is constant not the
character refered by it, so u can not make 'p' refer to
anyother location, but u can change the value of the charac
pointed by 'p'

Is This Answer Correct ?    10 Yes 4 No

what is the difference between const char *p, char const *p, const char* const p ..

Answer / bhargav

Const char *P ->
declares a pointer through which you may be able to access
a char but you can not change it through the said pointer.
But the pointer itself can be changed.

char const *p ->
in this the value is constant

const char* const p ->
both address and value are constants

Is This Answer Correct ?    13 Yes 22 No

Post New Answer

More C Interview Questions

Explain two-dimensional array.

0 Answers  


how to print value of e(exp1)up to required no of digits after decimal?

1 Answers  


What is a symbolic constant?

1 Answers  


Please write the area of a RIGHT ANGLED TRIANGLE.

1 Answers  


Synonymous with pointer array a) character array b) ragged array c) multiple array d) none

0 Answers  






I need testPalindrome and removeSpace #include <stdio.h> #define SIZE 256 /* function prototype */ /* test if the chars in the range of [left, right] of array is a palindrome */ int testPalindrome( char array[], int left, int right ); /* remove the space in the src array and copy it over to the "copy" array */ /* set the number of chars in the "copy" array to the location that cnt points t */ void removeSpace(char src[], char copy[], int *cnt); int main( void ) { char c; /* temporarily holds keyboard input */ char string[ SIZE ]; /* original string */ char copy[ SIZE ]; /* copy of string without spaces */ int count = 0; /* length of string */ int copyCount; /* length of copy */ printf( "Enter a sentence:\n" ); /* get sentence to test from user */ while ( ( c = getchar() ) != '\n' && count < SIZE ) { string[ count++ ] = c; } /* end while */ string[ count ] = '\0'; /* terminate string */ /* make a copy of string without spaces */ removeSpace(string, copy, &copyCount); /* print whether or not the sentence is a palindrome */ if ( testPalindrome( copy, 0, copyCount - 1 ) ) { printf( "\"%s\" is a palindrome\n", string ); } /* end if */ else { printf( "\"%s\" is not a palindrome\n", string ); } /* end else */ return 0; /* indicate successful termination */ } /* end main */ void removeSpace(char src[], char copy[], int *cnt) { } int testPalindrome( char array[], int left, int right ) { }

0 Answers  


what is the output of printf("%d",(scanf("%d",10));

10 Answers  


What is sizeof array?

0 Answers  


Why C language is a procedural language?

0 Answers   Ericsson,


mplementation of stack using any programing language

1 Answers   Marlabs,


#ifdef TRUE int I=0; #endif main() { int j=0; printf("%d %d\n",i,j); }

3 Answers   ADITI,


what is the difference between <stdio.h> and "stdio.h"

14 Answers   Invendis, Kanbay, Mastek, MathWorks,


Categories