280 views

1 Answer

1 votes
1 votes

In C, 

if we initialize like 

char *a = “Applied”; then it get written directly into executable which means it get into data segment not in stack or heap .

now the variable a is point to the location of the data segment. Data segment is generally read only so we cant update the value of “a”.

now here we are changing the value of a as *a++ ,which is not allowed. so depending upon on the compiler it will either show compile time error or just don’t print anything.

But according to standard gcc it should be error as it is trying to modifying the const string literal.

good read:https://stackoverflow.com/questions/1011455/is-it-possible-to-modify-a-string-of-char-in-c

Related questions

0 votes
0 votes
1 answer
1
its_vaibhav asked Jan 12, 2022
592 views
applied gate test seriesWhat is the output of the following c-code[ Note: Assume integer as 2 bytes] ?#include<stdio.h>int main(){ int x = 500;char *p=&x;*++p=2;printf(�...
2 votes
2 votes
2 answers
3
4 votes
4 votes
1 answer
4
ramakrushna asked Dec 31, 2021
1,335 views
The number of insertion sequences of the numbers {1,2,3,4,5,6,7} which would lead to the following BSTHow to tackle this kind of problem. Anyone!