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

Write a program to identify if a given binary tree is balanced or not.

688


Explain the advantages and disadvantages of macros.

627


Do you know the purpose of 'register' keyword?

642


Is main is a keyword in c?

610


What are the primitive data types in c?

579






How we can insert comments in a c program?

634


Describe the complexity of Binary search, Quicksort and various other sorting and searching techniques..

647


What is register variable in c language?

607


write a C program:There is a mobile keypad with numbers 0-9 and alphabets on it. Take input 0f 7 keys and then form a word from the alphabets present on the keys.

14965


Was 2000 a leap year?

633


What is the use of putchar function?

652


How can you increase the size of a statically allocated array?

619


What is the general form of #line preprocessor?

588


a c variable cannot start with a) an alphabet b) a number c) a special symbol d) both b and c above

686


Why do we use c for the speed of light?

606