Ask Question
2 August, 01:42

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.

+2
Answers (1)
  1. 2 August, 02:01
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers