Answer to Question #53468 in C for rajashree g.s.
Question #53468
#include<stdio.h>
int main()
{
int k=35;
printf("\n %d %d %d",k==35,k=50,k>40);
return 0;
}
please sir explain the logic behind this program clearly.
int main()
{
int k=35;
printf("\n %d %d %d",k==35,k=50,k>40);
return 0;
}
please sir explain the logic behind this program clearly.
Expert's answer
Code is executed as follows:
First the variable of type integer 'k' assigned the constant of 35
Second to the function 'printf' four parameters are passed. The first parameters is the string which state, what types of variables we want to display (formatting string). The remained three are the logic opperations that return result.
Command k==35 checks on equality the value of k and the constant 35. k=50, assigns value 50 to k and returns assigned value. The 'k>40' checks if k more than 40 and displays 1 if it satisfies the requirements.
The trick is in the fact that commants are executed from right to left, so the k>40 will be executed first, yielding the result of false ('0').
First the variable of type integer 'k' assigned the constant of 35
Second to the function 'printf' four parameters are passed. The first parameters is the string which state, what types of variables we want to display (formatting string). The remained three are the logic opperations that return result.
Command k==35 checks on equality the value of k and the constant 35. k=50, assigns value 50 to k and returns assigned value. The 'k>40' checks if k more than 40 and displays 1 if it satisfies the requirements.
The trick is in the fact that commants are executed from right to left, so the k>40 will be executed first, yielding the result of false ('0').
Need a fast expert's response?
Submit orderand get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Comments
Dear arpit,
please use panel for submitting new questions
printf("%d %d %d ",x++,++x,x++);
//solve this and explain this if possible.
Sear shivangi, please use panel for submitting new questions.
main( )
{
int x = 10, y = 20 ;
if ( x == y ) ;
printf ( "\n%d %d", x, y ) ;
Considering the expert's answer, the output will be:
0 50 0
int main()
{
int k=35;
printf("\n %d %d %d",k==35,k=50,k>40)
}
what is the output of this program sir. Here k is already assigned the value 35 know sir.please explain the logic sir.
Leave a comment