What could be Output of Program given below :-
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int a=500,b=100,c;
if (!a>=400)
b=300 ;
c=200;
printf("Value of b is :- %d \n Value of c is :- %d",b,c);
}
OUTPUT :-
so true returned by condition turns into false.
Now we are not having brackets after if condition if we don't have brackets around them then only next line after if condition is regarded as true statement and upnext statement is else statement
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int a=500,b=100,c;
if (!a>=400)
b=300 ;
c=200;
printf("Value of b is :- %d \n Value of c is :- %d",b,c);
}
OUTPUT :-
Can any one explain how this o/p came?
ReplyDeleteExplanation To Program :-
ReplyDeleteif (!a>=400)
b=300 ;
c=200;
Here first it is checked that (!a>=400) or (!500>=400)
so its true 500 is greater than 400 so it returns true but we have NOT sign in front so true returned by condition turns into false.
Now we are not having brackets after if condition if we don't have brackets around them then only next line after if condition is regarded as true statement and upnext statement is else statement
So as condition finally returned a false so upnext statement c= 200 ; will be executed