You are on page 1of 2

Given code:

#include <iostream>

using namespace std;

int main()
{
    int t,a,c;
    t=59,a=54,c=9;
    cout<<"Before if t="<<t<<"a="<<a<<"c="<<c;
    if(t>a||c++/3)
    cout<<"\n in if t="<<t<<"a="<<a<<"c="<<c;
    cout<<"\n after if t="<<t<<"a="<<a<<"c="<<c;
    t=50;
     cout<<"\n before if t="<<t<<"a="<<a<<"c="<<c;
     if(t>a||c++/3)
    cout<<"\n in if t="<<t<<"a="<<a<<"c="<<c;
    return 0;
}

The value of C is changed to 10 after executing second if statement. This is because value of t is
changed. In if, it compares the t and c values. So value of c changed.

In java
public class Main
{
 public static void main(String[] args) {
 
int t=59;
int a=54;
int c=9;

System.out.println("Before if t="+t+"a="+a+"c="+c);

if((t>a)||(c+1/3)>0){
System.out.println("Before if t="+t+"a="+a+"c="+c);}

System.out.println("Before if t="+t+"a="+a+"c="+c);
 t=50;
System.out.println("Before if t="+t+"a="+a+"c="+c);

if((t>a)||(c+1/3)>0)
{
System.out.println("Before if t="+t+"a="+a+"c="+c);}

 }
}

Output

The result is different in java compiler. the value of c is 9 in java. But in c++, the operator c+
+/3 change the result

You might also like