Comparison

Null value in comparison expression

Multiple choice question

Given the following PHP code, what will be the output?

function print_weather($weather){
if ($weather =="hot")
$weather_id = 0;
else if ($weather =="cold")
$weather_id = 1;
else
$weather_id=null;

if ($weather_id == null)
echo "Nice weather; ";
else
echo "Extreme weather; ";
}
print_weather("hot");
print_weather("cold");
print_weather(null);

assignment instead of comparison

Multiple choice question

What is this C language code do?

#include <stdio.h>

main()
{
  int c, nl;
  nl = 0;
  while ((c = getchar()) != EOF)
    if (c = '\n')
      ++nl;
  printf("%d\n", nl);
}

Syndicate content