Home » C Programming » Operators » Question
  1. What will be the final values of k and L in the following C code?
    #include <stdio.h>
    int n = 0;
    int main()
    {
    int k = (fun1() + fun2()) | fun2(); //bitwise or
    int L = fun2() | (fun1() + fun2()); //bitwise or
    }
    int fun1()
    {
    if (n == 0)
    return n + 1;
    else
    return n - 1;
    }
    int fun2()
    {
    return n++;
    }
    1. k value is 0 and L value is 0
    2. Compilation Error
    3. k value is 1 and L value is 1
    4. Runtime Error
    5. None of these
Correct Option: A

Compilation Error

main.c: In function ‘main’:
main.c:5:18: warning: implicit declaration of function ‘fun1’ [-Wimplicit-function-declaration]
int k = (fun1() + fun2()) | fun2(); //bitwise or
^~~~
main.c:5:27: warning: implicit declaration of function ‘fun2’ [-Wimplicit-function-declaration]
int k = (fun1() + fun2()) | fun2(); //bitwise or



Your comments will be displayed only after manual approval.