Home » C Programming » Functions » Question
  1. Which of the following is the correct output for the program given below?
    #include<stdio.h>
    int main ( )
    {
    int fun (int);
    int k = fun (20);
    printf ("%d\n" , --k) ;
    return 0 ;
    }

    int fun (int i)
    {
    return (k++) ;
    }
    1. 19
    2. 20
    3. 21
    4. 18
Correct Option: A

Step 1: int fun(int); Here we declare the prototype of the function fun().

Step 2: int i = fun(20); The variable i is declared as an integer type and the result of the fun(20) will be stored in the variable i.

Step 3: int fun(int k){ return (k++); } Inside the fun() we are returning a value return(k++). It returns 20. because k++ is the post-increment operator.

Step 4: Then the control back to the main function and the value 20 is assigned to variable k.

Step 5: printf("%d\n", --k); Here --k denoted pre-increment. Hence it prints the value 19.



Your comments will be displayed only after manual approval.