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
-
strconcat(string $glue, array $pieces)
-
implode ( string $glue , array $pieces )
-
strcmp(array $pieces, string $concat, int $elementNumber)
-
arrayConcat(array $pieces, string $concat, string $EOF)
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.
-
$var = new asoc_array("key"->"value","key2"->"value2");
-
$var = array("key"=>"value","key2"=>"value2");
-
$var = new ArrayList("key,value","key1,value1");
-
$var = new List(Of Associative)["key"=>"value","key1","value1"];
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.
-
asort($array)
-
ksort($array)
-
krsort($array)
-
usort($array)
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.
-
$result = mysql_obtain_rows($query);
-
$result = mysql_executeNonQuery($query);
-
$result = mysql_query($query);
-
$record = mysql_fetch_array($result)
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.
-
pg_numrows($result)
-
postregSQL_numRows($result)
-
mysql_num_rows($result)
-
ora_num_rows
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.
-
The same program logic can be used with objects of several related types.
-
Variables can be re-used in order to save memory.
-
Constructing new objects from old objects of a similar type saves time.
-
Polymorphism is a dangerous aspect of inheritance and should be avoided.
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.
-
One per defined class.
-
One per constructor definition.
-
As many as the program needs.
-
One per program
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.
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.
A
Correct answer
Explanation
java.lang.Object is the root class of the Java class hierarchy. Every class implicitly extends Object unless it explicitly extends another class. It's a fundamental class in the Java core API.
C
Correct answer
Explanation
sizeof(2.0) evaluates to sizeof(double) because 2.0 is a double literal by default in C. On most modern systems, a double occupies 8 bytes, not 4 (float) or 2 (some int types).
-
2
-
compiler error
-
runtime error
-
4
-
0
D
Correct answer
Explanation
The comma operator (2,4) evaluates expressions left-to-right and returns the value of the rightmost expression. Therefore, a receives the value 4, not 2 or 0.
-
anna
-
compile time error
-
anna4
-
non of the above
-
garbage
C
Correct answer
Explanation
printf("anna") prints "anna" and returns 4 (the count of characters printed). The outer printf then prints this return value, resulting in the output "anna4".
-
30
-
20
-
syntax error
-
garbage
D
Correct answer
Explanation
(arr+2) evaluates to the memory address of arr[2], not the value 30 at that location. Using %d to print an address produces an arbitrary large number that appears as garbage. To print the value, use *(arr+2) or arr[2].
-
I hate U
-
I love U
-
non of the above
-
error
A
Correct answer
Explanation
1.1 stored in float (me) has less precision than 1.1 stored in double (you). Due to different rounding errors in their binary representations, me and you are not exactly equal, so the else branch executes.
-
2 2
-
1 2
-
compiler error
-
non of the above
B
Correct answer
Explanation
The dereferenced char pointer '*p' has a size of 1 byte. On legacy 16-bit architectures assumed by this classic C question, pointers have a size of 2 bytes, resulting in the output '1 2'. On modern systems, pointer sizes are larger.