Awesome q2a theme
0 votes
8 views
#include<stdio.h>
int fun(char *str1)
{
    char *str2=str1;
        while(*++str1)
            return(str1-str2);
}
int main()
{
    char *str="geeksquiz";
    printf("%d",fun(str));
        return 0;

}

this question is from geeksforgeeks.com in that the answer is ‘9’ but i compiled in gnu gcc compiler the answer is ‘1’

how?
in Programming by (169 points) | 8 views

1 Answer

0 votes

Here the important line in code is 

while(*++str1);

If there is no semicolon after while loop then answer is $1$ and if there is a semicolon after while loop answer is $9$.

by (178 points)
Welcome to GATE CSE Doubts, where you can ask questions and receive answers from other members of the community.
932 questions
596 answers
1,885 comments
81,474 users