Given two sorted lists of size m and n respectively. The number of comparisons needed in the worst case by the merge sort algorithm will be?
include
int main()
{
int n;
for (n = 9; n!=0; n--)
printf("n = %d", n--);
return 0;
}
The variable n will never evaluate to 0 so the loop will run for infinite times.
include
int main()
{
int i = -5;
while (i <= 5)
{
if (i >= 0)
break;
else
{
i++;
continue;
}
printf("LogicGuns");
}
return 0;
}
The loop will break when i becomes 0 so nothing gets printed.
include
int main() {
int x=4, y, z;
y = --x;
z = x--;
printf("%d, %d, %d\n", x, y, z);
return 0;
}
In the statement " y = --x ", the value of x is decremented and gets stored in y i.e. y = 3.
In the statement " z = x--", the value of x i.e. 3 is stored in z then, it is decremented and becomes x=2.
D is correct. It defines an anonymous inner class instance, which also means it creates an instance of that new anonymous class at the same time. The anonymous class is an implementer of the Runnable interface, so it must override the run() method of Runnable.
Option A is incorrect because it doesnt override the run() method, so it violates the rules of interface implementation.
Option B and C use incorrect syntax.
Option B is correct because in an interface all methods are abstract by default therefore they must be overridden by the implementing class. The Runnable interface only contains 1 method, the void run() method therefore it must be implemented.
include
int message();
int main() {
int x,y,z;
x=y=z=-1;
z=++x && ++y || ++z;
printf(" x=%d y=%d z=%d\n", x,y,z);
return 0;
}
The operator `&&` has higher priority than the operator `||`. In the expression " z= (++x && ++y) || ++z", the value of x is incremented to 0 i.e. false value. Since, the 1st condition of && evaluates to false, 2nd condition of && operator is not tested and y remains unchanged.
Now, expression becomes "z = 0 || ++z". If the first condition of || operator evaluates to false, the 2nd condition of the operator will be tested also. Thus, value of z is incremented to 0. Finally, the result of the expression i.e. 0 is assigned to z.