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

what is the output of following program ? void main() { int i=5; printf("%d %d %d %d %d ",i++,i--,++i,--i,i); }

10 Answers  


main() { int i=5,j=10; i=i&=j&&10; printf("%d %d",i,j); }

1 Answers  


Write a program to model an exploding firecracker in the xy plane using a particle system

0 Answers   HCL,


main() { extern int i; i=20; printf("%d",sizeof(i)); }

2 Answers  


What are the files which are automatically opened when a C file is executed?

1 Answers  






main() { { unsigned int bit=256; printf("%d", bit); } { unsigned int bit=512; printf("%d", bit); } } a. 256, 256 b. 512, 512 c. 256, 512 d. Compile error

1 Answers   HCL,


main( ) { static int a[ ] = {0,1,2,3,4}; int *p[ ] = {a,a+1,a+2,a+3,a+4}; int **ptr = p; ptr++; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); *ptr++; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); *++ptr; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); ++*ptr; printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr); }

2 Answers   Persistent,


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

6 Answers  


#include<stdio.h> main() { char s[]={'a','b','c','\n','c','\0'}; char *p,*str,*str1; p=&s[3]; str=p; str1=s; printf("%d",++*p + ++*str1-32); }

2 Answers   CNSI,


What is your nationality?

1 Answers   GoDB Tech,


How can u say that a given point is in a triangle? 1. with the co-ordinates of the 3 vertices specified. 2. with only the co-ordinates of the top vertex given.

1 Answers  


main() { printf("%d, %d", sizeof('c'), sizeof(100)); } a. 2, 2 b. 2, 100 c. 4, 100 d. 4, 4

18 Answers   HCL, IBM, Infosys, LG Soft, Satyam,


Categories