593 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


Deprecated: Implicit conversion from float-string "1634997454.580" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 796

Deprecated: Implicit conversion from float-string "1634997454.580" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 801

Deprecated: Implicit conversion from float-string "1634997454.580" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 802

Deprecated: Implicit conversion from float-string "1634997454.580" to int loses precision in /var/www/html/qadb/qa-include/app/format.php on line 803
1.1k
views
1 answers
0 votes
debanjan sarkar asked Aug 21, 2015
1,133 views
Find the output of the following c code- main() { char *ptr="gatebuddy"; *(ptr)++; ptr++; printf("%s\n",ptr); }
1.3k
views
1 answers
1 votes
Sahil Vidyarthi asked Aug 23, 2014
1,328 views
Explain the output :-int b[3][4] = {{1,2,3,4}, {5,6,7,8}, {9,10,11,12}};int p;p = (int )b;cout << (long)*p << "\t" << (long)(*p+1) << "\t" << (long)(*p+2);//long is used...
935
views
2 answers
3 votes
sabir asked Nov 24, 2015
935 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...
685
views
3 answers
0 votes
lalitver10 asked Oct 23, 2021
685 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...