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 web technology
  1. strconcat(string $glue, array $pieces)
  2. implode ( string $glue , array $pieces )
  3. strcmp(array $pieces, string $concat, int $elementNumber)
  4. arrayConcat(array $pieces, string $concat, string $EOF)
Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

In PHP, the implode() function is an alias of join(). Both functions join array elements with a glue string. The other options (strconcat, strcmp, arrayConcat) are either unrelated string comparison functions or fictitious functions that do not exist in PHP's standard library.

Multiple choice technology web technology
  1. $var = new asoc_array("key"->"value","key2"->"value2");
  2. $var = array("key"=>"value","key2"=>"value2");
  3. $var = new ArrayList("key,value","key1,value1");
  4. $var = new List(Of Associative)["key"=>"value","key1","value1"];
Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

PHP associative arrays are created using the array() function with the => operator to associate keys with values. Option B shows the correct syntax: $var = array("key"=>"value", "key2"=>"value2"). Option A uses incorrect -> syntax and non-existent constructor. Option C is Java-style syntax. Option D is C# style syntax.

Multiple choice technology web technology
  1. asort($array)
  2. ksort($array)
  3. krsort($array)
  4. usort($array)
Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

krsort() sorts an associative array by key in reverse order (descending) while maintaining key-value associations. ksort() sorts ascending by keys. asort() sorts ascending by values. usort() sorts by values using a custom comparison function and doesn't maintain key associations.

Multiple choice technology web technology
  1. $result = mysql_obtain_rows($query);
  2. $result = mysql_executeNonQuery($query);
  3. $result = mysql_query($query);
  4. $record = mysql_fetch_array($result)
Reveal answer Fill a bubble to check yourself
C,D Correct answer
Explanation

mysql_query() executes a SQL query on the MySQL server and returns a result resource. mysql_fetch_array() fetches a row from the result set as an array. Options A and B are fictional functions that don't exist in PHP's MySQL extension.

Multiple choice technology web technology
  1. pg_numrows($result)
  2. postregSQL_numRows($result)
  3. mysql_num_rows($result)
  4. ora_num_rows

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

pg_numrows() is the PostgreSQL function to get the number of rows in a result set. mysql_num_rows() is the MySQL equivalent. Options B and D are incorrect function names - postregSQL_numRows has a typo and ora_num_rows is not the correct Oracle function name.

Multiple choice technology programming languages
  1. The same program logic can be used with objects of several related types.

  2. Variables can be re-used in order to save memory.

  3. Constructing new objects from old objects of a similar type saves time.

  4. Polymorphism is a dangerous aspect of inheritance and should be avoided.

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

Polymorphism allows the same code to work with different types of objects that share a common interface or base class. This enables writing more flexible and reusable code. Options B and C describe benefits unrelated to polymorphism. Option D is incorrect - polymorphism is a core OOP benefit, not something to avoid.

Multiple choice technology programming languages
  1. One per defined class.

  2. One per constructor definition.

  3. As many as the program needs.

  4. One per program

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

A class is a template - you can create as many objects (instances) of a class as your program needs, limited only by available memory. There's no built-in limit of one object per class, constructor, or program. Objects are created using the 'new' keyword and can be instantiated repeatedly.

Multiple choice technology programming languages
  1. True

  2. False

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

This is False due to constant ambiguity. When a class implements two interfaces that both define the same constant (PI), Java cannot determine which interface's constant to reference. This causes a compilation error. The constant must be explicitly qualified with the interface name (e.g., MyInterface1.PI) to resolve the ambiguity.