Open In App

Output of C programs | Set 58 (operators)

Last Updated : 02 Oct, 2017
Improve
Improve
Like Article
Like
Save
Share
Report

Prerequisite : Operators in C

Q.1 What is the output of this program?




#include <iostream>
using namespace std;
int main()
{
    printf("value is = %d", (10 ++));
    return 0;
}


Options
a) 10
b) 11
c) compile time error
d) run time error

ans: c

Explanation : lvalue required as increment operator operate only on variables and not constant values.

Q.2 What is the output of this program?




#include <iostream>
using namespace std;
int main()
{
    int i = 0, j = 1, k = 2, m;
    m = i++ || j++ || k++;
    printf("%d %d %d %d", m, i, j, k);
    return 0;
}


Options

a) 1 1 2 3
b) 1 1 2 2
c) 0 1 2 2
d) 1 2 3 3

ans:- b

Explanation : Once the value of expression is true in OR, latter expression will not evaluated hence j = 1 is assigned to m .

Q.3 What is the output of this program?




#include <iostream>
using namespace std;
int main()
{
    int y = 10;
    if (y++ > 9 && y++ != 10 && y++ > 11)
        printf("%d", y);
    else
        printf("%d", y);
    return 0;
}


Options
a) 11
b) 12
c) 13
d) none of above

ans: c

Explanation : and operator(&) is used so whole expression is evaluated even if the first part is true.

Q.4 What is the output of this program?




#include <iostream>
using namespace std;
int main()
{
    int i = 10;
    i = !i > 14;
    printf("i=%d", i);
    return 0;
}


Options
a) i=1
b) i=0
c) i=10
d) none of these

ans:- b

Explanation : Not oprerator(!) has more precedence than greater than operator(>) so 0>14 is evaluated false.

Q.5 What is the output of this program?




#include <iostream>
using namespace std;
int main()
{
    int a = 3, b = 5, c, d;
    c = a, b;
    d = (a, b);
    printf("c=%d d=%d", c, d);
    return 0;
}


Options
a) c=3 d=5
b) c=5 d=5
c) can’t be determined
d) none of these

ans : a

Explanation : The precedence of ‘(‘ is greater as compared to ‘, ‘ so firstly a is assigned in c and then b is assigned in d.

Q.6 What is the output of this program?




#include <iostream>
using namespace std;
int main()
{
    int y = 10;
    if (y++ > 9 && y++ != 11 && y++ > 11)
        printf("%d", y);
    else
        printf("%d", y);
    return 0;
}


Options
a) 11
b) 12
c) 13
d) 14

ans: b

Explanation : y++!=11 gets false, so y++>11 will not be evaluated.



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads