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

Write a C program to add two numbers before the main function is called.

11 Answers   Infotech, TC,


How we will connect multiple client ? (without using fork,thread)

3 Answers   TelDNA,


Write a program that produces these three columns sequence nos. using loop statement Sequence nos. Squared Squared + 5 1 1 6 2 4 9 3 9 14 4 16 21 5 25 30

1 Answers   GoDB,


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

1 Answers   Value Labs,


#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  






int i; main(){ int t; for ( t=4;scanf("%d",&i)-t;printf("%d\n",i)) printf("%d--",t--); } // If the inputs are 0,1,2,3 find the o/p

2 Answers  


¦void main() ¦{ ¦int i=10,j; ¦ j=i+++i+++i; ¦printf("%d",j); ¦getch(); ¦} ¦ output:-30 but in same question if we write as- ¦void main() ¦{ ¦int i=10; ¦ int j=i+++i+++i; ¦printf("%d",j); ¦getch(); ¦} ¦ output:-33 why output is changed from 30 to 33. Can any body answer...

3 Answers  


What is the problem with the following code segment? while ((fgets(receiving array,50,file_ptr)) != EOF) ;

1 Answers  


Predict the Output: int main() { int *p=(int *)2000; scanf("%d",2000); printf("%d",*p); return 0; } if input is 20 ,what will be print

2 Answers  


write a c program to Create a registration form application by taking the details like username, address, phone number, email along with password and confirm password (should be same as password).Ensure that the password is of 8 characters with only numbers and alphabets. Take such details for 5 users and display the details. In place of password display “****”. (Use Structures).

0 Answers   CDAC, College School Exams Tests,


main() { int i; clrscr(); for(i=0;i<5;i++) { printf("%d\n", 1L << i); } } a. 5, 4, 3, 2, 1 b. 0, 1, 2, 3, 4 c. 0, 1, 2, 4, 8 d. 1, 2, 4, 8, 16

4 Answers   HCL,


#define f(g,g2) g##g2 main() { int var12=100; printf("%d",f(var,12)); }

3 Answers  


Categories