497 views
2 votes
2 votes
What is the output of the following program?
int main ( )
{
char *str = “Gate2018”
printf (“%d”, output (str)) ;
return 0;
}
int output(char *P1)
{
char *P2 = P1 ;
while (*++P1) ;
return (P1 – P2);
}

1 Answer

0 votes
0 votes

P1 is char pointer it will take only 1 Byte size and P2 pointer for p1 pointer 

it will increment p1 pointer until null occured so P2-P1 = 8 - 0 = 8

Related questions

4 votes
4 votes
1 answer
1
Akriti sood asked Dec 28, 2016
1,303 views
main () { if( i) { main (); printf("%d", i); } } 5 4 3 2 1 1 2 3 4 5 0 0 0 0 0 Compiler error
1 votes
1 votes
1 answer
2
Akriti sood asked Dec 20, 2016
317 views
#include<stdio.h int main() { int m[6] = {15, 11, 25, 30, 35, 45}; int p, q, r; p = ++m ; q = m ++; r = m[p++]; printf("%d, %d, %d", p, q, r); return 0; }
0 votes
0 votes
0 answers
3
Anirudh Kaushal asked Apr 6, 2022
191 views
#include<stdio.h struct marks { int p:3; int c:3; int m:2; }; void main() { struct marks s = {2, -6, 5}; printf("%d %d %d", s.p, s.c, s.m); }What does p:3 means here ?
0 votes
0 votes
0 answers
4
bts1jimin asked Jan 20, 2019
311 views