Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

What do you mean by recursion in c?

1064


What does the error message "DGROUP exceeds 64K" mean?

1178


Why is c called c?

972


What is the right type to use for boolean values in c? Is there a standard type?

973


Explain the difference between call by value and call by reference in c language?

1064


How is a macro different from a function?

1128


i want to know the procedure of qualcomm for getting a job through offcampus

2420


Which is an example of a structural homology?

1270


What is volatile variable in c?

1059


What are reserved words with a programming language?

1069


What is the use of static variable in c?

1052


The difference between printf and fprintf is ?

1226


Explain what is the benefit of using an enum rather than a #define constant?

1181


What is memory leak in c?

1071


Using functions, write a program that multiplies two arrays. Use the following functions: - Function ReadArray - Function MultiplyArrays - Function DisplayArrays

2305