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

#define DIM( array, type) sizeof(array)/sizeof(type) main() { int arr[10]; printf(“The dimension of the array is %d”, DIM(arr, int)); }

1 Answers  


How do you write a program which produces its own source code as its output?

7 Answers  


source code for delete data in array for c

1 Answers   TCS,


Declare an array of N pointers to functions returning pointers to functions returning pointers to characters?

1 Answers  


main() { char *p="GOOD"; char a[ ]="GOOD"; printf("\n sizeof(p) = %d, sizeof(*p) = %d, strlen(p) = %d", sizeof(p), sizeof(*p), strlen(p)); printf("\n sizeof(a) = %d, strlen(a) = %d", sizeof(a), strlen(a)); }

1 Answers  






String copy logic in one line.

11 Answers   Microsoft, NetApp,


main() { int a=2,*f1,*f2; f1=f2=&a; *f2+=*f2+=a+=2.5; printf("\n%d %d %d",a,*f1,*f2); }

6 Answers  


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

1 Answers  


void main() { if(~0 == (unsigned int)-1) printf(“You can answer this if you know how values are represented in memory”); }

1 Answers  


program to find magic aquare using array

4 Answers   HCL,


What are segment and offset addresses?

2 Answers   Infosys,


int swap(int *a,int *b) { *a=*a+*b;*b=*a-*b;*a=*a-*b; } main() { int x=10,y=20; swap(&x,&y); printf("x= %d y = %d\n",x,y); }

1 Answers  


Categories