Programming Language Syntax MCQs: 12 Solved Questions on Grammar, Tokens and Semantics

Solve 12 MCQs on syntax, tokens, pseudocode, C grammar and runtime behaviour. Each explanation identifies the rule and applies it.

KnowledgeGate Team

Exam prep & CS education

Updated 16 Oct 20268 min read

Syntax, tokens and semantics look like easy definitions until an MCQ mixes them with identifiers, C punctuation, translation or a short execution trace. Decide first whether the item tests legal form, program meaning or runtime behaviour. Choose an option before reading its answer, and label each item token, syntax, static rule or runtime semantics in the margin. The Coding & DSA category provides wider practice after you can separate token, grammar and meaning traps.

Programming language syntax MCQs: use the token, grammar, meaning test

Use a three-pass test. First, lexical analysis groups characters into tokens. Next, grammar checks whether that token sequence has a legal structure. Semantics then determines what the legal structure means. Add a fourth check for execution questions: substitute the values the question gives you and trace each statement in order.

Take total = count + 2; with count = 5. Its six tokens are identifier total, assignment operator =, identifier count, addition operator +, integer literal 2 and punctuator ;. The grammar rules <stmt> ::= <id> "=" <expr> ";" and <expr> ::= <id> "+" <number> accept that sequence. Its syntax is therefore valid. Under the given state, its runtime meaning is total = 5 + 2 = 7.

Keep those layers separate even when an option uses them loosely. Language Design in Programming Languages traces tokens through AST construction, type checking and evaluation. Here, the task is faster: classify each MCQ as lexical, syntactic, static-semantic or runtime-semantic.

Four stages for total = count + 2; with count = 5: the character stream, six labelled tokens, a parse tree, then the result total = 7.

Syntax, semantics and algorithm form: Questions 1-3

Question 1

UGC NET 2020, Paper I, November

Which of the following statements are true?

(A) An algorithm may produce no output

(B) An algorithm expressed in a programming language is called a computer program

(C) An algorithm is expressed in a graphical form known as flowchart.

(D) An algorithm can have infinite sequence of instructions.

Choose the correct answer from the options given below :

  • A. (A) and (B) only

  • B. (A), (B) and (D) only

  • C. (C) and (D) only

  • D. (B) and (C) only

Answer: D. (B) and (C) only

Under the conventional textbook definition tested by this item, an algorithm expressed in a programming language is a program, and a flowchart is its graphical representation. Finiteness makes statement (D) false, while the requirement for at least one output makes statement (A) false. Option D means the fourth answer choice, not statement (D).

Question 2

CDAC CCAT 2017

_______ refer to the names of functions, variables, arrays, classes etc.,

  • A. Operators

  • B. Punctuators

  • C. Manipulators

  • D. Identifiers

Answer: D. Identifiers

An identifier is a programmer-supplied name for an entity. In int count = 5;, count is the identifier, int a keyword, = an operator, 5 a literal and ; a punctuator, eliminating A, B and C.

Question 3

Accenture 2025

The structure or format of data is called ___________

  • A. Syntax

  • B. Semantics

  • C. Struct

  • D. Formatting

Answer: A. Syntax

Syntax describes form and arrangement, while semantics describes meaning. In x = 4 + 3;, the token order follows assignment syntax and evaluation makes x equal to 7; “Struct” is a construct and “Formatting” is too informal here.

Pseudocode, syntax rules and C tokens: Questions 4-6

Question 4

Infosys 2025; Hexaware 2023; CoCubes 2024, Computer Science

Keep the statement language ______________ while writing a pseudo code.

  • A. Dependent

  • B. Independent

  • C. Case sensitive

  • D. Capitalized

Answer: B. Independent

Pseudocode communicates an algorithm without requiring one language's exact syntax. REPEAT 3 TIMES: total <- total + 2 describes three additions of 2, a net increase of 3 × 2 = 6, without committing to C, Java or Python punctuation.

Question 5

What does the term 'Syntax' refer to in programming languages?

  • A. The set of rules that defines the combinations of symbols that are considered to be correctly structured programs

  • B. The process of finding and fixing errors

  • C. A specific type of computer hardware

  • D. The history of a programming language

Answer: A. The set of rules that defines the combinations of symbols that are considered to be correctly structured programs

Syntax is the rule system for legal symbol and token arrangements. x = 2 + 3; satisfies a simple assignment grammar, whereas = x 2 + 3; does not in ordinary C-like grammar, even if a reader guesses the intended arithmetic.

Question 6

CDAC CCAT 2017

Which one of the following is an operator in 'C'?

  • A. @

  • B. $

  • C. ,

  • D. @@

Answer: C. ,

C has a comma operator. In x = (2, 5);, it evaluates 2 and then 5, so x = 5; this operator use differs from a comma acting only as a separator, and @, $ and @@ are not C operators. Review the broader token, pattern and lexeme distinction in Lexical Analysis in Compiler Design.

Translation and C grammar constraints: Questions 7-9

Question 7

DSSSB 2024, Computer Science, TGT

Which of the following statement(s) is/are correct regarding Assembly language?

I. An assembler converts (or assembles) the symbolic program of an Assembly language into its equivalent machine program.

II. A program written in an assembly language is machine dependent.

  • A. Both I and II

  • B. Only II

  • C. Only I

  • D. Neither I nor II

Answer: A. Both I and II

An assembler translates symbolic mnemonics and operands into the target machine's binary instruction encoding, so I is true. Those mnemonics, registers and encodings belong to a processor architecture, making the source machine dependent and II true.

Question 8

CDAC CCAT 2017

Which one of the following is correct w.r.t control expression in switch statement?

  • A. Only int can be used

  • B. Both char and int can be used

  • C. Any data type can be used

  • D. Only void cannot be used

Answer: B. Both char and int can be used

C switch control expressions use integral types, so both switch(2) and switch('A') are admissible forms. Floating-point and arbitrary types are not accepted merely because they are non-void, making B the only matching statement.

Question 9

CDAC CCAT 2017

Consider the following C program snippet:

unsigned x;

Which one of the following is correct?

  • A. Compile-time error because the data type is not mentioned

  • B. It accepts and takes int by default

  • C. It accepts and takes char by default

  • D. Runtime error

Answer: B. It accepts and takes int by default

In a C declaration, unsigned alone is shorthand for unsigned int. Thus unsigned x; successfully declares x and is equivalent to unsigned int x;, with neither a compile-time nor a runtime error.

Control-flow and declaration semantics: Questions 10-12

Question 10

CDAC CCAT 2017

Which one of the following is correct w.r.t the usage of break and continue statements in C?

  • A. break can be used in for, if and while statement body

  • B. continue can be used only in for loop body

  • C. break can be used only in for and if statement body

  • D. break and continue can be used in for, while and do-while loop body. But only break can be used in switch body

Answer: D. break and continue can be used in for, while and do-while loop body. But only break can be used in switch body

break exits the nearest loop or switch, while continue advances the nearest enclosing loop to its next iteration. Both apply directly to for, while and do-while. A switch creates a target for break, not for continue; a continue inside a switch is valid only when an enclosing loop supplies its target. In the intended exam framing, D is therefore the matching option. For more rule-based practice, use C Language: Concepts, MCQs, Coding Questions.

Question 11

CDAC CCAT 2019

Function definitions are present in the Standard header files.

  • A. Yes, they are the library files

  • B. No, only declarations are present

  • C. No, both declarations and definitions are present

  • D. No, only definitions are present in header files

Answer: B. No, only declarations are present

For this question, B is the intended answer: a header normally supplies declarations so the compiler can type-check calls, while the compiled implementation comes from the library during linking. Including the appropriate header declares printf, but that header is not itself the compiled library implementation. Real C headers can also contain macros and static inline definitions, so “only declarations” is an exam simplification rather than a universal rule.

Question 12

Infosys 2025

How many times will the print statement be executed?

Integer a, b, c

Set a = 8, b = 10, c = 6

If (a > c AND (b + c) > a)

Print a

End if

If (c > b OR (a + c) > b)

Print b

End if

If ((b + c) MOD a EQUALS 0)

Print c

End if

  • A. 2

  • B. 3

  • C. 1

  • D. 0

Answer: B. 3

Trace the three independent conditions. First, 8 > 6 and 10 + 6 = 16 > 8, so a prints; second, 6 > 10 is false but 8 + 6 = 14 > 10 is true, so b prints. Third, (10 + 6) MOD 8 = 16 MOD 8 = 0, so c prints, for three executions in total.

Programming language syntax MCQ traps and the next revision step

Common error

Rule to write beside it

Confusing token category with grammar role

Classify the token before parsing the sequence

Treating syntax as meaning

Syntax is legal form; semantics is meaning

Assuming pseudocode follows one language

Pseudocode is language-independent

Reading unsigned as a missing type

unsigned means unsigned int

Stopping after Question 12's first true branch

Its three if statements are independent

If you score below 10/12, wait 48 hours and retake only the category you missed. Before selecting an option, write a one-line reason that names the rule, such as “comma is an operator”, instead of repeating the answer.

The short version is: classify, parse, then trace. NET learners can use NTA-UGC-NET Paper - 2 as the structured next step.