Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  Consider the following C function.int strg(ch... Start Learning for Free
Consider the following C function.
int strg(char *str)
{
    static int temp=0;
    if(*str!=NULL)
    {
        temp++;
        strg(++str);
    }
    else
    {
        return temp;
    }
}​
What is the output of strg(abcabcbb)?
    Correct answer is '8'. Can you explain this answer?
    Most Upvoted Answer
    Consider the following C function.int strg(char *str){static int temp=...
    Explanation:
    The given C function 'strg' takes a string as input and recursively counts the number of characters in the string until it reaches the end of the string. The static variable 'temp' is used to store the count of characters.

    Execution:
    When the function 'strg' is called with the string "abcabcbb", the following steps are executed:

    1. The function is called with the string "abcabcbb".
    2. The first character of the string is 'a', which is not equal to NULL. So, the 'temp' variable is incremented by 1.
    3. The function 'strg' is called again with the remaining string "bcabcbb".
    4. The first character of the string is 'b', which is not equal to NULL. So, the 'temp' variable is incremented by 1.
    5. The function 'strg' is called again with the remaining string "cabcbb".
    6. The first character of the string is 'c', which is not equal to NULL. So, the 'temp' variable is incremented by 1.
    7. The function 'strg' is called again with the remaining string "abcbb".
    8. The first character of the string is 'a', which is not equal to NULL. So, the 'temp' variable is incremented by 1.
    9. The function 'strg' is called again with the remaining string "bcbb".
    10. The first character of the string is 'b', which is not equal to NULL. So, the 'temp' variable is incremented by 1.
    11. The function 'strg' is called again with the remaining string "cbb".
    12. The first character of the string is 'c', which is not equal to NULL. So, the 'temp' variable is incremented by 1.
    13. The function 'strg' is called again with the remaining string "bb".
    14. The first character of the string is 'b', which is not equal to NULL. So, the 'temp' variable is incremented by 1.
    15. The function 'strg' is called again with the remaining string "b".
    16. The first character of the string is 'b', which is not equal to NULL. So, the 'temp' variable is incremented by 1.
    17. The function 'strg' is called again with the remaining string "".
    18. The first character of the string is NULL, so the 'else' part of the function is executed.
    19. The value of 'temp', which is 8, is returned.

    Therefore, the output of the function 'strg("abcabcbb")' is 8.
    Free Test
    Community Answer
    Consider the following C function.int strg(char *str){static int temp=...
    This question is related to recursion. hence loop itself.
    because function strg calling itself with parameters. outer function strg (char *str) read single character starting from first character and function strg (++str) is incredible. there is 8 character. hence loop executive 8 time and function return value 8. hence answer is 8.
    Explore Courses for Computer Science Engineering (CSE) exam

    Top Courses for Computer Science Engineering (CSE)

    Consider the following C function.int strg(char *str){static int temp=0;if(*str!=NULL){temp++;strg(++str);}else{return temp;}}​What is the output of strg(abcabcbb)?Correct answer is '8'. Can you explain this answer?
    Question Description
    Consider the following C function.int strg(char *str){static int temp=0;if(*str!=NULL){temp++;strg(++str);}else{return temp;}}​What is the output of strg(abcabcbb)?Correct answer is '8'. Can you explain this answer? for Computer Science Engineering (CSE) 2024 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about Consider the following C function.int strg(char *str){static int temp=0;if(*str!=NULL){temp++;strg(++str);}else{return temp;}}​What is the output of strg(abcabcbb)?Correct answer is '8'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Consider the following C function.int strg(char *str){static int temp=0;if(*str!=NULL){temp++;strg(++str);}else{return temp;}}​What is the output of strg(abcabcbb)?Correct answer is '8'. Can you explain this answer?.
    Solutions for Consider the following C function.int strg(char *str){static int temp=0;if(*str!=NULL){temp++;strg(++str);}else{return temp;}}​What is the output of strg(abcabcbb)?Correct answer is '8'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
    Here you can find the meaning of Consider the following C function.int strg(char *str){static int temp=0;if(*str!=NULL){temp++;strg(++str);}else{return temp;}}​What is the output of strg(abcabcbb)?Correct answer is '8'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Consider the following C function.int strg(char *str){static int temp=0;if(*str!=NULL){temp++;strg(++str);}else{return temp;}}​What is the output of strg(abcabcbb)?Correct answer is '8'. Can you explain this answer?, a detailed solution for Consider the following C function.int strg(char *str){static int temp=0;if(*str!=NULL){temp++;strg(++str);}else{return temp;}}​What is the output of strg(abcabcbb)?Correct answer is '8'. Can you explain this answer? has been provided alongside types of Consider the following C function.int strg(char *str){static int temp=0;if(*str!=NULL){temp++;strg(++str);}else{return temp;}}​What is the output of strg(abcabcbb)?Correct answer is '8'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Consider the following C function.int strg(char *str){static int temp=0;if(*str!=NULL){temp++;strg(++str);}else{return temp;}}​What is the output of strg(abcabcbb)?Correct answer is '8'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
    Explore Courses for Computer Science Engineering (CSE) exam

    Top Courses for Computer Science Engineering (CSE)

    Explore Courses
    Signup for Free!
    Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
    10M+ students study on EduRev