ALLInterview.com :: Home Page            
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Google
   
 
Categories >> Software >> Programming Languages >> C
 
 


 

 
 C interview questions  C Interview Questions (2266)
 C++ interview questions  C++ Interview Questions (1121)
 VC++ interview questions  VC++ Interview Questions (342)
 Delphi interview questions  Delphi Interview Questions (510)
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions (652)
Question
what is the difference between
const char *p, char const *p, const char* const p
 Question Submitted By :: C
I also faced this Question!!     Answer Posted By  
 
Answer
# 1
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 ?    166 Yes 10 No
Kumar Krishna
 
Answer
# 2
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 ?    112 Yes 48 No
Singamsa
 
 
 
Answer
# 3
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 ?    63 Yes 31 No
Vignesh1988i
 
Answer
# 4
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 ?    9 Yes 3 No
Magdaleen
 
Answer
# 5
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 ?    12 Yes 21 No
Bhargav
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
#include main() { int i=1,j=2; switch(i) { case 1: printf("GOOD"); break; case j: printf("BAD"); break; } } ME 6
/*what is the output for the code*/ void main() { int r; r=printf("naveen"); r=printf(); printf("%d",r); getch(); } CDAC 1
main() { int i = -3,j=2,k=0,m; m= ++i || ++j && ++k; printf("%d%d%d",i,j,k,m); } HCL 6
the format specified for hexa decimal is a.%d b.%o c.%x d.%u TCS 6
write aprogram for There is a mobile keypad with numbers 0-9 and alphabets on it. take input of 7 keys and then form a word from the alphabets present on those keys. Subex 1
Why does not use getgh(); and <conio.h> in c language. Elofic 2
When is an interface "good"?   1
How many ways are there to swap two numbers without using temporary variable? Give the each logic.   8
whenever a question is posted in a particular category in allinterview.com, Is there any facility to receive an indication mail. For eg: I need to receive an indication email, whenever a question is posted under the category “C Langauage”.   1
Write a function in c to find the area of a triangle whose length of three sides is given.   2
what is disadvantage of pointer in C Tech-Mahindra 13
Dear Sir, we are required the bubble sorting programs Regs Prem   1
 
For more C Interview Questions Click Here 
 
 
 
 
 


   
Copyright Policy  |  Terms of Service  |  Articles  |  Site Map  |  RSS Site Map  |  Contact Us
   
Copyright © 2013  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  KalAajKal.com