what is the difference between these initializations?
Char a[]=”string”;
Char *p=”literal”;
Does *p++ increment p, or what it points to?
Answer Posted / koti
Actually char a[ ]="string" in this scenario string constant is stored in read-only memory section and also stack section.in this case you can modify the string constant.that modifications are happened in stack section .so here
*a ++ men's
1 ) a is pointing to base address of string constant .
2 ) *a men's inside content that is 's'.
3 ) *a ++ men's incrementing the asci value of 's'. After that you can print this array like
Printf("%s",a);
O/P : ttring.
Coming to the *p ="literal" this scenario
1 ) *p is stored in stack section why because it is auto variable.
2 ) "literal" this string constant is stored in read-only memory section.
3 ) P is pointing to string constant Base addres
Here *p++ men's you are training to change read only memory section contact. so it is an error why because
You can't modified the read-only memory content.
Main difference is using arrays string constant is stored in both stack and read-only memory section.
Using pointers string constant is stored in read-only memory section only .
Thank you.
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Which is best linux os?
Simplify the program segment if X = B then C ← true else C ← false
What are directives in c?
What is meant by inheritance?
Write a program to compute the similarity between two strings - The program should get the two strings as input - Then it will output one single number which is the percentage of similarity between the two strings
How to set file pointer to beginning c?
What are the c keywords?
Write a program on swapping (100, 50)
What is data structure in c language?
Which is an example of a structural homology?
What are external variables in c?
Do you know the purpose of 'register' keyword?
What are the benefits of organizational structure?
#define PRINT(int) printf("int = %d ",int) main() {< BR> intx,y,z; x=03;y=02;z=01; PRINT(x^x); z<<=3;PRINT(x); y>>=3;PRINT(y); }
When c language was developed?