4,487 views

2 Answers

0 votes
0 votes
It will throw an error because you didn't point to a valid memory location(or a variable name) when you made the assignment char *p = 0. Hence, undefined behaviour.
0 votes
0 votes

*p=<anything other than a variable>

This line is executed in the following way.

<anything other than a variable or a pointer> is a literal and is stored in the read-only part of the memory and the pointer is pointing to that memory. We can write *p as p[0]. So, when p[0]='a' is being executed, it wants to modify a data inside the read-only part and this is illegal. Hence it will give runtime error.

Related questions

0 votes
0 votes
2 answers
1
shiva0 asked Jul 18, 2018
857 views
#include<stdio.h main() { char c = 'A'+255; printf("%c", c); }
1 votes
1 votes
2 answers
2
sushmita asked Sep 28, 2018
442 views
void main() { char*s[]={"iceland","Greenland","Ireland","Switzerland"}; char ptr[]={s+3,s+2,s+1,s}; char *p=ptr; printf(\%s ", ++p); printf(\%s ",*(*++p+3); printf(\%s ...
2 votes
2 votes
2 answers
4
atulcse asked Jan 15, 2022
687 views
Consider the following programint find (int n) { int a = 1; for (i = 1; i < = n; i ++) for (j = 1; j < = i; j++) for (k = 1; k <= j, k++) a = a + 1; ...