Comparativo do IF em linguagem JAVA, C++ e PHP

--------------------------------------------------------------------------------

# ---- #

# JAVA #

# ---- #

https://ideone.com/9WRE1K

/* package whatever; // don't place package name! */

import java.util.*;

import java.lang.*;

import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */

class Ideone

{

public static void main (String[] args) throws java.lang.Exception

{

int var;

var = true ? '1' : false ? '2' : '3'; // Converte string em int (ASCII)

System.out.println(var);

}

}

stdout 49

------------------------

https://ideone.com/DsqFs7

/* package whatever; // don't place package name! */

import java.util.*;

import java.lang.*;

import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */

class Ideone

{

public static void main (String[] args) throws java.lang.Exception

{

char var;

var = true ? '1' : false ? '2' : '3';

System.out.println(var);

}

}

stdout 1

-----------------------------------------------------------------------------------

# --- #

# C++ #

# --- #

https://ideone.com/SVoZzH

#include <iostream>

using namespace std;

int main() {

char $var;

$var = true ? '1' : false ? '2' : '3';

cout << "$var is " << $var;

return 0;

}

stdout $var is 1

-------------------------

https://ideone.com/KLyI7E

#include <iostream>

using namespace std;

int main() {

int $var;

$var = true ? '1' : false ? '2' : '3'; // Converte string em int (ASCII)

cout << "$var is " << $var;

return 0;

}

stdout $var is 49

----------------------------------------------------------

# --- #

# PHP #

# --- #

https://ideone.com/gFdjNg

<?php

$var = true ? '1' : false ? '2' : '3';

echo '$var is '.$var;

?>

stdout $var is 2