Please Give The Examples Of Semantic And Syntax Errors In C Language?
Hi everyone,
I have just started to learn programming and a kind of confused in semantic and syntax errors. Please provide me some examples to explain both the types of errors.
Hi everyone,
I have just started to learn programming and a kind of confused in semantic and syntax errors. Please provide me some examples to explain both the types of errors.
The basic difference between the semantic and syntax error is that, the semantic error occurs when there is fault in your “logic “whereas the syntax error occurs when there is error in the syntax of the sequence of character written.
Some of them are given below:
Semantic error
• Area of rectangle= length + breadth // the formula to find the area for rectangle is l*b
• 1/0
• If(a=b) // here you are assigning it not comparing
• x-=1 // add one to x
Syntax error
• #include // can’t give space between the #include and the angular braces
• printf(“hello”) // no ; after the printf statement
• scanf(“%d”, x); // not putting ampersand before the variable while using scanf
• if ()
{
{
}
// no closing all the curly brackets properly.