Computer Knowledge

Programming Languages and Compilers

2,284 Questions

Programming languages and compilers involve the rules, syntax, and semantics used to write and execute software programs. Key areas include scripting languages, object oriented concepts, and parsing algorithms like top down parsers. Practice these computer science questions to build proficiency for technical and computer knowledge exams.

Object oriented languagesScripting languagesCompilers and parsersProgramming syntax

Programming Languages and Compilers Questions

Multiple choice technology mainframe
  1. REPEAT 5 TIMES;instruction;END;

  2. DO J=1 TO 5;instruction;END;

  3. COUNTER = 1;DO WHILE COUNTER < 5;COUNTER = COUNTER + 1;instruction;END;

  4. REPEAT VARYING COUNTER FROM 1 BY 1 UNTIL COUNTER = 5;instruction;END;

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

PL/I uses the DO loop construct for iteration control. The correct syntax for repeating an instruction 5 times is DO J=1 TO 5; instruction; END; which creates a controlled loop with an index variable. The REPEAT keyword doesn't exist in PL/I, and the WHILE option would require different initialization and would execute only 4 times with < 5 condition.

Multiple choice technology mainframe
  1. after each declaration of a variable

  2. at the end of each instruction

  3. to end a DO instruction

  4. at the end of the program

  5. to end an IF instruction

Reveal answer Fill a bubble to check yourself
B,D,E Correct answer
Explanation

In PL/I, semicolons terminate statements rather than acting as separators. Thus, a semicolon is required at the end of each statement (instruction), to terminate groups like DO, and to terminate the program block. However, the options listed are slightly confusing as a DO instruction ends with a separate END statement, which contains a semicolon, but 'at the end of each instruction', 'at the end of the program', and 'to end an IF instruction' (which is terminated by a semicolon) align with PL/I statement terminator rules.

Multiple choice technology programming languages
  1. True

  2. False

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The exit() function is part of the C Standard Library, specifically in the cstdlib header (stdlib.h in C). It's used to terminate program execution and return a status code to the operating system. This is a standard function used throughout C and C++ programs for controlled program termination.

Multiple choice technology
  1. True

  2. False

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

COBOL and PASCAL are both high-level programming languages, not computer viruses. COBOL (Common Business-Oriented Language) is used in business and finance applications, while PASCAL was designed for teaching programming concepts. Viruses are malicious software that replicate themselves, which these languages are not.

Multiple choice technology programming languages
  1. A

  2. B

  3. the code will fail

  4. None of the above

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Calling B-&gt;new() inherits new from package A. In A::new, the single-argument bless {} blesses the object into the current package (A). Thus, \$obj is an instance of A, and \$obj-&gt;foo() calls A::foo which returns 'A'.

Multiple choice technology programming languages
  1. empty string

  2. value

  3. the code will fail

  4. None of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The code fails because init() is called before bless() returns a fully constructed object. When init() attempts $self->{key} = 'value', $self is still an unblessed hash reference (not yet an object of class A), but more critically, calling init() inside new() before the bless completes means $self lacks proper object context. Perl's bless() operation must complete before the object can properly call its own methods. The correct pattern is to bless first, then initialize, or use a post-bless initialization hook.

Multiple choice technology programming languages
  1. 2

  2. 6

  3. 106

  4. I don't like undefs

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The array @a contains (1, undef, 2). The loop iterates three times: first val=1, foo(1) returns 2, sum becomes 2; second val=undef, foo(undef) dies with error message, eval catches it ($@ is true), so sum += 100 making sum = 102; third val=2, foo(2) returns 4, sum becomes 106. The print outputs 106. The eval block traps the die() on undefined input, adding 100 instead of failing.

Multiple choice technology programming languages
  1. undef

  2. 0

  3. 1

  4. 2

  5. code will fail

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

When Perl evaluates exists $var->{key1}->{key2}, it autovivifies (auto-creates) the intermediate hash structure even though the key2 doesn't exist. This means $var->{key1} is created as an empty hash. The exists check returns false (key2 doesn't exist), so the assignment inside the if block doesn't execute. However, the autovivication already happened, leaving $var with one key (key1). keys(%{$var}) returns 1.

Multiple choice technology programming languages
  1. abcd

  2. acbd

  3. cadb

  4. code will fail

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

BEGIN blocks execute at compile time in declaration order, while END blocks execute at runtime in reverse declaration order (LIFO - last in, first out). The two BEGIN blocks print 'a' then 'c'. The two END blocks are declared in order (prints 'b' then 'd'), but execute in reverse order, so 'd' prints before 'b'. Final output: 'ac' from BEGIN blocks, then 'db' from END blocks, yielding 'cadb'.

Multiple choice technology mainframe
  1. (A) Sections

  2. (B) Paragraphs

  3. (C) Sentences

  4. (D) Statements.

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

In COBOL Procedure Division, only Sections are optional. You must have at least one Paragraph, which contains Sentences, which are composed of Statements. This hierarchy is: Sections (optional) > Paragraphs (required) > Sentences (required) > Statements (required). A procedure can consist of a single paragraph with sentences, without any sections, making sections the only truly optional element.

Multiple choice technology mainframe
  1. (A) Start

  2. (B) Rewrite

  3. (C) Delete

  4. (D) Update.

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

In COBOL, START, REWRITE, and DELETE are valid input/output verbs used to perform operations on files. UPDATE is not a valid COBOL verb; modifying an existing record is accomplished using the REWRITE verb. Thus, option D is the correct choice.

Multiple choice technology programming languages
  1. Math.round(Math.random() * (high - low)) + low

  2. Math.round(Math.random())

  3. Math.round(Math.random())+ low

  4. None of the baove

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Math.random() returns a value in the range [0, 1). Multiplying it by the range size (high - low), rounding the result using Math.round(), and shifting it by adding low correctly generates a random integer in the closed interval [low, high]. Other choices fail to scale or shift the output correctly.