syntactically correct but semantically incorrect examples in programming?
Syntactically and semantically. Syntactically means grammatically wrong. In any language if syntax is not valid that comes under syntactically wrong. But if some thing is semantically wrong it means that the syntax is acceptable but meaningless.
For ex:
#include<stdio.h>
int main(){
int x;
printf("%d",x);
}
We define x but there is no any value of x so it can be anything which is called garbage value.
#include<stdio.h>
int main(){
int x;
printf("%d",x)
}
Semicolon is missing in line 4 so this is syntactically wrong.
Another example
#include<stdio.h>
int main(){
int add(int x, int y){
return x-y;
}
printf("%d",add(3,4));
}
This is also semantically wrong but syntactically correct because the add function in the program is for adding purpose but used for finding difference.
Get Answers For Free
Most questions answered within 1 hours.