Ask Question
13 May, 08:22

Write the definition of a function named counter that receives no parameters and returns 0 the first time it is invoked, returns 1 the next time it is invoked, then 2, 3 and so on.

+5
Answers (1)
  1. 13 May, 11:59
    0
    int counter ()

    {

    static int xvalue = 0;

    return (xvalue++);

    }

    Explanation:

    The first line of code declares the function and its return type integer. Then we create a static variable xvalue and initialize to 0. the statement return (xvalue++) ensures that at each method call, the value of integer is increased by 1
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write the definition of a function named counter that receives no parameters and returns 0 the first time it is invoked, returns 1 the next ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers