Computer Science, asked by 114730, 1 year ago

what do you mean by Syntax and semantic errors?

Answers

Answered by Gopukrishnan3223
2

Syntax is about the structure or the grammar of the language. It answers the question: how do I construct a valid sentence? All languages, even English and other human (aka "natural") languages have grammars, that is, rules that define whether or not the sentence is properly constructed.

Here are some C language syntax rules:

separate statements with a semi-colonenclose the conditional expression of an IF statement inside parenthesesgroup multiple statements into a single statement by enclosing in curly bracesdata types and variables must be declared before the first executable statement (this feature has been dropped in C99. C99 and latter allow mixed type declarations.)

Semantics is about the meaning of the sentence. It answers the questions: is this sentence valid? If so, what does the sentence mean? For example:

x++; // increment foo(xyz, --b, &qrs); // call foo

are syntactically valid C statements. But what do they mean? Is it even valid to attempt to transform these statements into an executable sequence of instructions? These questions are at the heart of semantics.

Consider the ++ operator in the first statement. First of all, is it even valid to attempt this?

If x is a float data type, this statement has no meaning (according to the C language rules) and thus it is an error even though the statement is syntactically correct.If x is a pointer to some data type, the meaning of the statement is to "add sizeof(some data type) to the value at address x and store the result into the location at address x".If x is a scalar, the meaning of the statement is "ad
Answered by guptagitanshu
2
In C++,
Syntax error occurs when there are mistakes that violates the rules of writing the program code.
Semantics Error occurs when a particular statement or program block has no meaning i.e it does not return any value or gives a perfect output.
Similar questions