Programmer questions

What is the output for the following 3 code snippets?

$x = 3;

if (4 < $x) {
print "The quick brown fox jumps over the lazy dog.";
} else {
print "She sells seashells on the seashore.";
}
$x = 1;
$x = ++$x * 2;
print $x;
$x = 1;
$x = $x++ * 2;
print $x;
Advertisements

One thought on “Programmer questions

  1. Answer for question 1 is “She sells seashells on the seashore.” The reason why the expression (4 = 4), but maybe it is time to change.

    Answer for question 2 is 4. When we use “++$x” instead of the more common “$x++”, the value is incremented before being multiplied.

    Answer for question 3 is 2.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s