Open In App
Related Articles

C | Operators | Question 6

Improve Article
Save Article
Like Article

What is the output of below program?

#include <stdio.h>
int foo(int* a, int* b)
    int sum = *a + *b;
    *b = *a;
    return *a = sum - *b;
int main()
    int i = 0, j = 1, k = 2, l;
    l = i++ || foo(&j, &k);
    printf("%d %d %d %d", i, j, k, l);
    return 0;

(A) 1 2 1 1
(B) 1 1 2 1
(C) 1 2 2 1
(D) 1 2 2 2

Answer: (A)

Explanation: The control in the logical OR goes to the second expression only if the first expression results in FALSE. The function foo() is called because i++ returns 0(post-increment) after incrementing the value of i to 1. The foo() function actually swaps the values of two variables and returns the value of second parameter. So, values of variables j and k gets exchanged and OR expression evaluates to be TRUE.

Quiz of this Question

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 28 Jun, 2021
Like Article
Save Article
Similar Reads