1,194 views
3 3 votes

What will be the output of the program ?

#include<stdio.h>

int main()
{
    int i=4, j=8;
    printf("%d, %d, %d\n", i|j&j|i, i|j&j|i, i^j);
    return 0;
}
  A.
12, 12, 12
  B.
112, 1, 12
  C.
32, 1, 12
  D.
-64, 1, 12

3 Answers

4 4 votes

It is actually a compiler dependent question as it is not specified in which order the arguments of printf() will be evaluated..According to CDECL convention which most of the compilers use , arguments are evaluated right to left..

So i XOR j will be found first which is given by : 4 XOR 8  =  12

Then  i |  j & j | i , so here AND is performed first..We know x AND x = x only.

So  i | j | i   =  4 OR 8 OR 4   =   12

Similarly the last argument from right which is same as middle one is also calculated as 12..

Hence A) should be the correct option,,

Position:
Show:

Related questions

1 1 vote
1 1 answer
286
286 views
khanshahima4 asked Sep 24
286 views
1. If precedence tells me which operator has priority, and associativity tells me how to handle operators at the same level, then why do I need a separate concept called ...
14 14 votes
1 1 answer
1.4k
1.4k views
GO Classes asked Jul 2
1,350 views
Assume:$\texttt{short = 2 bytes}$, $\texttt{int = 4 bytes}$, $\texttt{char = 1 byte}$$\texttt{int}$ needs $4$-byte alignment and the final structure size is rounded to a ...
18 18 votes
2 2 answers
753
753 views
GO Classes asked Jul 2
753 views
Assume:struct Student { double gpa; }; struct Student alice; struct Student *sptr = &alice;Which of the following correctly assigns $\texttt{4.0}$ to $\texttt{alice.gpa}$...
10 10 votes
1 1 answer
561
561 views
GO Classes asked Jul 2
561 views
Consider the following code idea from the source:typedef struct { double x, y; } Point; void reset(Point p) { p.x = p.y = 0; } int main() { Point a = {12.0, 42.0}; Point ...