1. const char *a;
2. char* const a;
3. char const *a;
-Differentiate the above declarations.
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
Is the following code legal? typedef struct a aType; struct a { int x; aType *b; };
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"); }
#define a 10 int main() { printf("%d..",a); foo(); printf("%d..",a); return 0; } void foo() { #undef a #define a 50 }
Is this code legal? int *ptr; ptr = (int *) 0x400;
void main() { char far *farther,*farthest; printf("%d..%d",sizeof(farther),sizeof(farthest)); }
main() { char *p = “ayqm”; printf(“%c”,++*(p++)); }
29 Answers IBM, TCS, UGC NET, Wipro,
plz send me all data structure related programs
int a=1; printf("%d %d %d",a++,a++,a); need o/p in 'c' and what explanation too
main() { show(); } void show() { printf("I'm the greatest"); }
What is full form of PEPSI
void main() { int i=i++,j=j++,k=k++; printf(“%d%d%d”,i,j,k); }
Give a one-line C expression to test whether a number is a power of 2.