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); } Programming in C data-structures programming-in-c + – Shivi rao asked Oct 11, 2017 Shivi rao 526 views answer comment Share Follow See all 4 Comments See all 4 4 Comments reply srestha commented Oct 11, 2017 reply Follow Share https://gateoverflow.in/158494/output-of-program 0 votes 0 votes srestha commented Oct 11, 2017 reply Follow Share what is ans given? 0 votes 0 votes Shubhanshu commented Oct 11, 2017 reply Follow Share It should be 8. 0 votes 0 votes Shivi rao commented Oct 11, 2017 reply Follow Share 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..? 0 votes 0 votes Please log in or register to add a comment.
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 Rishi yadav answered Oct 15, 2017 Rishi yadav comment Share Follow See all 0 reply Please log in or register to add a comment.