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 |
main() { char *p = "hello world"; p[0] = 'H'; printf("%s", p); } a. Runtime error. b. “Hello world” c. Compile error d. “hello world”
main() { char c=' ',x,convert(z); getc(c); if((c>='a') && (c<='z')) x=convert(c); printf("%c",x); } convert(z) { return z-32; }
main() { int i=_l_abc(10); printf("%d\n",--i); } int _l_abc(int i) { return(i++); }
# include <stdio.h> int one_d[]={1,2,3}; main() { int *ptr; ptr=one_d; ptr+=3; printf("%d",*ptr); }
Write a C program to print look and say sequence? For example if u get the input as 1 then the sequence is 11 21 1211 111221 312211 12112221 .......(it counts the no. of 1s,2s etc which is in successive order) and this sequence is used in run-length encoding.
Write a procedure to implement highlight as a blinking operation
Is the following code legal? void main() { typedef struct a aType; aType someVariable; struct a { int x; aType *b; }; }
main() { char not; not=!2; printf("%d",not); }
main() { int i; printf("%d",scanf("%d",&i)); // value 10 is given as input here }
#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); }
void main() { char a[]="12345\0"; int i=strlen(a); printf("here in 3 %d\n",++i); }
main(){ char a[100]; a[0]='a';a[1]]='b';a[2]='c';a[4]='d'; abc(a); } abc(char a[]){ a++; printf("%c",*a); a++; printf("%c",*a); }