What Will Be The Value Of Ans After The Following Code Has Been Executed?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
What will be the value of ans after the following code has been executed?
int x = 90, y = 55, ans = 10;
if (x == y );
ans *= 2;
Answer: The variable ans will be equal to 20 after the above code has been executed.
the conditional statements assist in decision making which is based on certain conditions. The conditions are either true or false but some of the statements have an alternative such as if one of the conditions is not fulfilled then the other condition may run. The types of the conditional statements are described below:
If statement:
An IF statement work only if the given condition is true otherwise the program is terminated. The syntax of the statements are:
If (condition) {
}
If else:
It is a two-way statement; in it, the program is executed if the condition is fulfilled or not. The syntax of the statement is:
If (condition)
{
statement
}
Else {
}
If else if:
In the if-else if statement’s the code run for more than two conditions, it is also known as the multiple path decision. The syntax is in the following:
If (condition)
{
statement’s
}
Else if (condition) {
}
Else {
statement
}
Nested if-else:
The statement is useful if the program needs two or more test conditions, it is referred to as the multi-way selection statement. If the sequence of the decision is present in a statement then if-else is used in a nested statement. The syntax of the given statement is listed in the following:
If (condition)
{
If (condition)
{
Statement 1;
}
Else {
Statement 2;
}
}
Else
{
Statement 3;
}