in Programming
117 views
0 votes
0 votes

What is the output of the following c-code ?



      A.It prints the APPLIED
      B.It prints the DEILPPA
      C.It prints nothing
      D.None of the above
in Programming
117 views

Subscribe to GO Classes for GATE CSE 2022

1 Answer

1 vote
1 vote

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