Question

Explain why the following if statement results in syntax error in C, Java, and C#? if...

Explain why the following if statement results in syntax error in C, Java, and C#?

   if (x==1) y = 2 else y = 3;
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer :

The correct statement of ' if ' statement is :

                       if(condition) {
                      // Statements inside body of if
                            }
                       else {
                     //Statements inside body of else
                            }

This is the only valid syntax in which ' if ' statement is written otherwise it will result in syntax error ( for the above question compiler will treat the whole 'if statement' in continuation as 'condition' which will further show syntax error)  .

for the above question, the correct syntax will be:

if (x==1)

y=2 ;

else

y=3 ;

Add a comment
Know the answer?
Add Answer to:
Explain why the following if statement results in syntax error in C, Java, and C#? if...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In each of the below syntax exercises, determine the output that results from running the specified...

    In each of the below syntax exercises, determine the output that results from running the specified MATLAB program.  If there is no output because an error results, write “ERROR” and then explain why the error occurs. clear; clc a = 3; b = 2; c = 1; for m = 1:3 for n = 1:3 if n < m      a = b - c elseif n == m b = a + 1; else c = 2*b + a; end end...

  • The following grammar describes the syntax of the Java if statement: <stmt> rightarrow <matched> | <unmatched>...

    The following grammar describes the syntax of the Java if statement: <stmt> rightarrow <matched> | <unmatched> <matched> rightarrow if (<logic_expr>) <matched> else <matched> | <non_if_stmt> <unmatched> rightarrow if (<logic_expr>) <stmt> | if (<logic_expr>) <matched> else <unmatched> Using this grammar, draw a parse tree for the following sentential form: if (<logic_expr>) if (<logic_expr>) <non_if_stmt> else <non_if_stmt>

  • Q10: Which of the following is not an error (either a syntax error or a logic...

    Q10: Which of the following is not an error (either a syntax error or a logic error)? Neglecting to include an action in the body of a while statement that will eventually cause the condition to become false. Spelling a key word (such as while or if) with a capitalized first letter. Using a condition for a while statement that is initially false. An infinite loop. Q11: How many times is the body of the loop below executed? int counter;...

  • in java Assuming that x is 11 and y is 9, EXPLAIN why the output of...

    in java Assuming that x is 11 and y is 9, EXPLAIN why the output of the following code is ????? if (x < 10) if ( y < 10) ​System.out.println(“*****”); else ​System.out.println(“#####”); ​System.out.println(“?????”);

  • Specify whether each of the following errors is a syntax error, a runtime error or a...

    Specify whether each of the following errors is a syntax error, a runtime error or a logic error: a. using single quotes where command needs double quotes _____ b. dollar and cents amount on a bill is not formatted correctly _____ c. divide a number by zero _____ (8) Evaluate the following expressions: a. fabs (-25.2) b. pow(4.0, 3.0) c. squareroot (400) d. fabs (8.2) e. squareroot (-400) f. floor(-6.7) g. floor(6.7) h. ceil(-4.1) (4) Indicate which of the following...

  • Eclipse Java Oxygen Question 11 pts A compile-time error occurs when Group of answer choices c....

    Eclipse Java Oxygen Question 11 pts A compile-time error occurs when Group of answer choices c. there’s a syntax error in a Java statement a. the Java compiler can’t be located b. bytecodes can’t be interpreted properly c. there’s a syntax error in a Java statement Flag this Question Question 21 pts An error that lets the application run but produces the wrong results is known as a Group of answer choices d. syntax error c. logic error a. runtime...

  • Why am I getting this error? 3 errors found: File: /Users/FDM/Desktop/ITSC_1212_InitialSetup/ITSC_1212/bookClasses/Assignment3Part2.java [line: 57] Error: <identifier> expected...

    Why am I getting this error? 3 errors found: File: /Users/FDM/Desktop/ITSC_1212_InitialSetup/ITSC_1212/bookClasses/Assignment3Part2.java [line: 57] Error: <identifier> expected File: /Users/FDM/Desktop/ITSC_1212_InitialSetup/ITSC_1212/bookClasses/Assignment3Part2.java [line: 57] Error: <identifier> expected File: /Users/FDM/Desktop/ITSC_1212_InitialSetup/ITSC_1212/bookClasses/Assignment3Part2.java [line: 59] Error: class, interface, or enum expected public class Assignment3Part2 { // public static void main(String [] args) throws InterruptedException { String filename; if (args.length > 0) { // got a filename passed into program as a parameter // don't change this part of the code needed by TA for grading filename = args[0];...

  • CGALLENE 4.2: More syntax errors. ACTIVITY Each cout statement has a syntax error. Type the first...

    CGALLENE 4.2: More syntax errors. ACTIVITY Each cout statement has a syntax error. Type the first cout statement, and press Run to observe the error message. Fix the error, and run again. Repeat for the second, then third, cout statement cout << "Num: "<< songnum << endl; cout << int songNum << endl; cout << songNum " songs" << endl; Note: These activities may test code with different test values. This activity will perform two tests: the first with songNum-5,...

  • What is the output of the following code snippet? (If there is some kind of syntax...

    What is the output of the following code snippet? (If there is some kind of syntax error indicate this by marking "error" in your answer choice) 1.        int laps = 8;        if (laps++ > --laps)               laps += 2;        else if (--laps > (laps - 1))               laps += 4;        else if (++laps)               laps -= 3;        cout << laps << endl; 2. What is the output of the following code snippet?     int j = 47;     int i = 8;     j =...

  • What is the output of the following code snippet? (If there is some kind of syntax...

    What is the output of the following code snippet? (If there is some kind of syntax error indicate this by marking "error" in your answer choice) 1.        int fly = 5; int x;        if (fly-- > 5)               x = 5;        else               x = 2;        if (x++ > 3)               cout << x;        cout << fly << endl; 2.   int i = 0;        bool b = i == 0 || i++ > 0;        if (!b)               cout << i << endl;        else               cout...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT