Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Q: Briefly explain what is meant by the syntax and the semantics of a

Programming language. You Give an example to illustrate the difference between a

Syntax error and a semantics error.

A: The syntax of a language is its grammar, and the semantics is its

Meaning. A java program with a syntax error cannot be compiled. A program with a

Semantic error can be compiled and run, but gives an incorrect result. A missing

Semicolon in a program is an example of a syntax error, because the compiler will

Find the error and report it. If N is an integer variable, then the statement "franc =

1/N;" is probably an error of semantics. The value of 1/N will be 0 for any N greater

Than 1. It's likely so that the programmer meant to say 1.0/N.

Q: What does the computer do when it executes a variable declaration?

Statement. Give an example.

A: A variable is a "box", or location, in the computer's memory that has a

Name. The box is holds a value of some specified type. A variable declaration

Statement is a statement such as

Into x;

Which creates the variable x. When is the computer executes a variable declaration, it

Creates the box in memory and associates a name (in this case, x) with that box.

Later in the program, that variable can be referred to by name.

You might also like