What will be the final values of i and j in the following C code?
#include <stdio.h>
int x = 0;
int f()
{
if (x == 0)
return x + 1;
else
return x - 1;
}
int g()
{
return x++;
}
int main()
{
int i = (f() + g()) | g(); //bitwise or
int j = g() | (f() + g()); //bitwise or
}
#include <stdio.h>
int x = 0;
int f()
{
if (x == 0)
return x + 1;
else
return x - 1;
}
int g()
{
return x++;
}
int main()
{
int i = (f() + g()) | g(); //bitwise or
int j = g() | (f() + g()); //bitwise or
}
A. i value is 1 and j value is 1
B. i value is 0 and j value is 0
C. i value is 1 and j value is undefined
D. i and j value are undefined
Answer: Option C
Related Questions on C Fundamentals
What is the primary purpose of a function prototype in C?
A. Declare a variable
B. Declare a function
C. Define a function
D. Assign a value
What is the correct syntax for declaring a variable in C?
A. int variable_name;
B. variable_name = 5;
C. variable_name int;
D. int = variable_name;
Join The Discussion