1. const char *a;

2. char* const a;

3. char const *a;

-Differentiate the above declarations.

Answers were Sorted based on User's Feedback



1. const char *a; 2. char* const a; 3. char const *a; -Differentiate the above..

Answer / manoj ku. dalai

Explaining With the examples.........

1) const char *a="xyz" (string is constant, pointer is not)
*a='x' (error)
a="hi" (legal)

2) char* const a="xyz" (pointer is constant, String is not)
*a='x' (legal)
a="hi" (error)

3) char const *a="xz" (string is constant, pointer is not)
a*='x' (error)
a="hi" (legal)

Is This Answer Correct ?    2 Yes 0 No

1. const char *a; 2. char* const a; 3. char const *a; -Differentiate the above..

Answer / susie

Answer :

1. 'const' applies to char * rather than 'a' ( pointer to a
constant char )

*a='F' : illegal

a="Hi" : legal

2. 'const' applies to 'a' rather than to the value of
a (constant pointer to char )

*a='F' : legal

a="Hi" : illegal

3. Same as 1.

Is This Answer Correct ?    0 Yes 1 No

1. const char *a; 2. char* const a; 3. char const *a; -Differentiate the above..

Answer / srinivas

The answers for first and third case is fine,but in 2nd
case we cannot assign *a='F',becoz *a points to starting
address of the array you cannot change the value at that
address where the reference to that pointer is lost.

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More C Code Interview Questions

Is the following code legal? typedef struct a aType; struct a { int x; aType *b; };

1 Answers  


main() { int y; scanf("%d",&y); // input given is 2000 if( (y%4==0 && y%100 != 0) || y%100 == 0 ) printf("%d is a leap year"); else printf("%d is not a leap year"); }

1 Answers  


#define a 10 int main() { printf("%d..",a); foo(); printf("%d..",a); return 0; } void foo() { #undef a #define a 50 }

3 Answers  


Is this code legal? int *ptr; ptr = (int *) 0x400;

1 Answers  


void main() { char far *farther,*farthest; printf("%d..%d",sizeof(farther),sizeof(farthest)); }

2 Answers  






main() { char *p = “ayqm”; printf(“%c”,++*(p++)); }

29 Answers   IBM, TCS, UGC NET, Wipro,


plz send me all data structure related programs

2 Answers  


int a=1; printf("%d %d %d",a++,a++,a); need o/p in 'c' and what explanation too

1 Answers  


main() { show(); } void show() { printf("I'm the greatest"); }

2 Answers  


What is full form of PEPSI

0 Answers  


void main() { int i=i++,j=j++,k=k++; printf(“%d%d%d”,i,j,k); }

1 Answers  


Give a one-line C expression to test whether a number is a power of 2.

10 Answers   Microsoft,


Categories