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 |
C program to print magic square of order n where n > 3 and n is odd
void main() { int c; c=printf("Hello world"); printf("\n%d",c); }
main() { int i=5,j=6,z; printf("%d",i+++j); }
main() { char *a = "Hello "; char *b = "World"; clrscr(); printf("%s", strcat(a,b)); } a. Hello b. Hello World c. HelloWorld d. None of the above
#define DIM( array, type) sizeof(array)/sizeof(type) main() { int arr[10]; printf(“The dimension of the array is %d”, DIM(arr, int)); }
Write a routine that prints out a 2-D array in spiral order
How to count a sum, when the numbers are read from stdin and stored into a structure?
Write a C function to search a number in the given list of numbers. donot use printf and scanf
main() { int i=4,j=7; j = j || i++ && printf("YOU CAN"); printf("%d %d", i, j); }
Ramesh’s basic salary is input through the keyboard. His dearness allowance is 40% of basic salary, and house rent allowance is 20% of basic salary. Write a program to calculate his gross salary.
find simple interest & compund interest
#include <stdio.h> #define a 10 main() { #define a 50 printf("%d",a); }