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


Please Help Members By Posting Answers For Below Questions

How many keywords are there in c?

836


1234554321 1234 4321 123 321 12 21 1 1 12 21 123 321 1234 4321 1234554321

3463


What does %p mean c?

845


Explain can you assign a different address to an array tag?

873


can any one please explain, how can i access hard disk(physical address)? it is possible by the use of far,near or huge pointer? if yes then please explain......

1644


Why do we use stdio h and conio h?

873


What are the different properties of variable number of arguments?

932


What is a struct c#?

798


in any language the sound structure of that language depends on its a) character set, input/output function, its control structures b) character set, library functions, input/output functions its control structures c) character set, library functions, control sturctures d) character set, operators, its control structures

955


int far *near * p; means

3339


Linked lists -- can you tell me how to check whether a linked list is circular?

875


What is the purpose of type declarations?

901


How do I use void main?

864


What is an arrays?

863


What is main function in c?

812