575 views
1 votes
1 votes

consider following code segment  in c

main()

{

char * z="abc";

z[0]='x';

printf("%s",z);

}

what will be behavior of the program

a>compiler error   b>runtime error c>no error prints xbc

d>no error prints abc

2 Answers

0 votes
0 votes
If contents of string constant is modified, the behavior is undefined in C.

Related questions

0 votes
0 votes
1 answer
1
debanjan sarkar asked Aug 21, 2015
1,118 views
Find the output of the following c code- main() { char *ptr="gatebuddy"; *(ptr)++; ptr++; printf("%s\n",ptr); }
3 votes
3 votes
2 answers
3
sabir asked Nov 24, 2015
872 views
Main () { int a [3] [4] = $\begin{pmatrix} 1&2&3&4 \\ 5&6&7&8 \\ 9&10&11&12 \\ \end{pmatrix}$ printf ("\n% u% u% u", a[0]+1, * (a[0] + 1), *(*(a + 0)+1)); }What is the o...
0 votes
0 votes
3 answers
4
lalitver10 asked Oct 23, 2021
668 views
#include <stdio.h>int main(){ int a=20; int *ptr=&a; int x=a; printf ("%p\n",&*ptr); printf ("%p\n",&a); return 0;}Why both printf() line printing the s...