The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+2 votes
80 views
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);
}
asked in Programming by Junior (785 points) | 80 views
0
0
what is ans given?
0
It should be 8.
0
Given ans is 8 but my doubt was it should depend on size of data type ( int )as size of int is not specified ..here..?

1 Answer

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

answered by Loyal (6.5k points)


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

37,019 questions
44,592 answers
126,850 comments
43,663 users