retagged by
533 views
1 votes
1 votes

Determine the output-

#include <stdio.h>
int main(void) 
{
	char *p="gateoverflow";
	*(p+5)='z';
	printf("%s",p);
	return 0;
}
retagged by

1 Answer

Best answer
5 votes
5 votes

The declaration :

char *p  =  "gateoverflow" ;

so this suggests that "gateoverflow" is a string constant..And for string constant :

Base address can be changed but content cannot be changed.. 

And reverse happens for array declaration like :

char p[15] = "Gateoverflow" .Here base address cannot be changed but content can be changed..

Hence the above code results to runtime error.. 

selected by

Related questions

0 votes
0 votes
1 answer
1
stblue asked Oct 18, 2017
742 views
#include <stdio.h>int main(){ int a[] = {50, 60, 10, 30, 40, 20 }; int *b[] = {a+3, a+4, a, a+2, a+1, a+5 }; int c = b; c++; printf("%u, %u, %u\n", c-b, *...
1 votes
1 votes
1 answer
2
0 votes
0 votes
1 answer
3
0 votes
0 votes
1 answer
4
Desert_Warrior asked May 16, 2016
753 views
main() { int i=-1; -i; printf("i = %d, -i = %d \n",i,-i); }