CSS Computer Science (Optional) — Paper-I, Section-A, Topic II subtopic. The building blocks that define any programming language.

Core Concepts

Syntax vs Semantics — Example

int x = 5 / 0;

Contrast with:

int x = 5 0;

Grammar and Rules

💻 Code Examples: C & C++

The syntax-vs-semantics example from above, made runnable, plus tokens labelled:

C:

#include <stdio.h>
int main(void) {
    int x = 5 / 2;       /* syntactically valid; semantics: integer division -> 2 */
    // int y = 5 0;       // would be a SYNTAX error -- missing operator, won't compile
    printf("%d\n", x);    // tokens: printf ( "%d\n" , x ) ;
    return 0;
}