723 views

1 Answer

0 0 votes
The output should be 6.

There needs to be a correction on line 5, it should be -   char *p2=p1;

Now, p1 will be incremented till the end of str. So in the end, p1 will be 6.

And there will be no change in p2. So p2=0;

Hence, it will return    p1-p2=6-0=6
Position:
Show:

Related questions

9 9 votes
2 2 answers
339
339 views
GO Classes asked Jun 24
339 views
What is the output of the following code?#include <stdio.h void change(char *p) { p = 'X'; *(p + 3) = '\0'; } int main() { char str[] = "GATE"; change(str); printf("%s",...
7 7 votes
2 2 answers
315
315 views
GO Classes asked Jun 24
315 views
What is the output of the following code?#include <stdio.h int main() { char str[] = "HELLO"; char *p = str + 1; *(p + 2) = 'A'; printf("%s %c", str, *p); return 0; }$\te...
6 6 votes
2 2 answers
328
328 views
GO Classes asked Jun 24
328 views
What is the output of the following code?#include <stdio.h int main() { char str[] = {'C', 'S', 'E', '\0', 'X'}; printf("%s %c", str, str[4]); return 0; }$\texttt{CSE X}$...
7 7 votes
2 2 answers
402
402 views
GO Classes asked Jun 23
402 views
What is the output of the following code?#include <stdio.h int main() { char str[] = "CODE"; char *p = str; p++; *p = 'A'; printf("%s %c", str, *(p + 2)); return 0; }$\te...