What is the difference between syntax and semantics in programming languages?

后端 未结 10 1926
长情又很酷
长情又很酷 2020-12-04 04:51

What is the difference between syntax and semantics in programming languages (like C, C++)?

10条回答
  •  伪装坚强ぢ
    2020-12-04 05:12

    Syntax refers to the structure of a language, tracing its etymology to how things are put together.
    For example you might require the code to be put together by declaring a type then a name and then a semicolon, to be syntactically correct.

    Type token;
    

    On the other hand, the semantics is about meaning. A compiler or interpreter could complain about syntax errors. Your co-workers will complain about semantics.

提交回复
热议问题