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 generate random numbers in c?

658


Is python a c language?

548


Can you subtract pointers from each other? Why would you?

554


How would you obtain the current time and difference between two times?

719


Draw a diagram showing how the operating system relates to users, application programs, and the computer hardware ?

2112






provide an example of the Group by clause, when would you use this clause

1701


A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers

644


When should a type cast be used?

573


a linearly ordered set of data elements that have the same structure and whose order is preserved in storage by using sequential allocation a) circular b) ordinary c) array d) linear list

629


Is main an identifier in c?

593


What is queue in c?

569


What are the back slash character constants or escape sequence charactersavailable in c?

678


What is the difference between malloc() and calloc() function in c language?

594


which of the following shows the correct hierarchy of arithmetic operations in C a) (), **, * or/,+ or - b) (),**,*,/,+,- c) (),**,/,*,+,- d) (),/ or *,- or +

1176


How do you determine a file’s attributes?

595