Home » Programming & Data Structure » Programming and data structure miscellaneous » Question

Programming and data structure miscellaneous

Programming & Data Structure

  1. The value of j at the end of the execution of the following C program int incr (int i) { static int count = 0; count = count + i; return (count); } main () {
    int i j; for (i = 0; i < = 4; i + +) j = incr (i); } is
    1. 10
    2. 4
    3. 6
    4. 7
Correct Option: A

Count is static variable in incr(). Statement static int count = 0 will assign count to 0 only in first call. Other calls to this function will take the old values of count. Count will become 0 after the call incr(0). Count will become 1 after the call incr(1) Count will become 3 after the call incr(2) Count will become 6 after the call incr(3) Count will become 10 after the call incr(4)



Your comments will be displayed only after manual approval.