• retagged by
1,163 views
1 1 vote

Determine the output-

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

1 Answer

Best answer
5 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
Position:
Show:

Related questions

0 0 votes
1 answers 1 answer
1.3k
1.3k views
stblue asked Oct 18, 2017
1,322 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 1 vote
1 answers 1 answer
2.9k
2.9k views
Desert_Warrior asked May 16, 2016
2,907 views
#include<stdio.h void foo(char *); int main() { char *string = "Hello"; foo(string); printf("%s",string); return 0; } void foo(char *a) { while(*a) { *a += 1; a++; } }(a)...
0 0 votes
1 1 answer
755
755 views
Desert_Warrior asked May 16, 2016
755 views
#include <stdio.h int main(void) { char a[5] = { 1, 2, 3, 4, 5 }; char *ptr = (char*)(&a + 1); printf("%d %d\n", *(a + 1), *(ptr - 1)); return 0; }options are : (a) Compi...
0 0 votes
1 answers 1 answer
1.2k
1.2k views
Desert_Warrior asked May 16, 2016
1,185 views
main() { int i=-1; -i; printf("i = %d, -i = %d \n",i,-i); }