Q:: What will be the output::
void main()
{
int x;
scanf("%d",&x);
if((x)&&(!x))
printf("Hello");
if((x)||(!x))
printf("World");
}
(A) HelloWorld (B) World
(C)Hello (D) Depends upon value of 'x'
void main()
{
int x;
scanf("%d",&x);
if((x)&&(!x))
printf("Hello");
if((x)||(!x))
printf("World");
}
(A) HelloWorld (B) World
(C)Hello (D) Depends upon value of 'x'
Ans:: (B)
Explanation::
In C programming the logical not operator performs the complement operation i.e. it converts a condition from true to false or false to true. In other words it converts a non-zero number to zero and zero to one.
So the first 'if' will always be false and the second 'if' always be true.
No comments:
Post a Comment