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
-
x: 6 y: 16
-
x: 10 y: 26
-
x: 10 y: 15
-
x: 6 y: 15
D
Correct answer
Explanation
The postfix increment operator x++ evaluates to the current value of x (which is 5) before incrementing it to 6. Thus, y += 5 sets y to 15, and x is updated to 6, matching the correct output.
-
Ounce
-
WebInspect
-
IBM RAD
-
None of the above
A
Correct answer
Explanation
Ounce (IBM Rational AppScan) is a static source code analyzer that identifies security vulnerabilities without executing the code. WebInspect is dynamic, RAD is an IDE, not an analyzer.
-
Coldfusion
-
PHP
-
Python
-
ASP
B
Correct answer
Explanation
PHP uses as its standard opening and closing tags, with the short form ?> also available when short_open_tag is enabled in configuration. This syntax embeds PHP code within HTML files. Other languages like Coldfusion use , Python is not typically embedded in HTML this way, and ASP uses <% %> tags.
-
for (var i = 0; i < arr.length; i++) { // some code here }
-
for (var i = 0, len = arr.length; i < len; i++) { // some code here }
-
for (var i = arr.length; i--; ) { // some code here }
-
for ( i = 0; i < arr.length; i++) { // some code here }
C
Correct answer
Explanation
A decrementing loop checking against zero (i--) is historically the fastest in JavaScript because the termination check does not require querying a property (arr.length) or comparing variables on every iteration. Other options perform redundant length lookups or property evaluations inside the loop condition.
-
JavaScript
-
Java
-
Perl
-
Rexx
A
Correct answer
Explanation
JavaScript was originally named Mocha when it was created by Brendan Eich at Netscape in 1995. It was briefly renamed LiveScript before being officially launched as JavaScript. The name change was partly a marketing move to capitalize on Java's popularity, though the languages are unrelated.
-
It is immutable
-
Simplifies strng manipulations
-
Simplifies concurrent multithreaded programming
-
None of the above
C
Correct answer
Explanation
System.String is immutable, which makes it inherently thread-safe. Multiple threads can access and read the same String object simultaneously without locks or synchronization, unlike StringBuilder which requires explicit coordination in multithreaded environments.
-
COBOL
-
CICS
-
REXX
-
Easytrieve
B
Correct answer
Explanation
COBOL, REXX, and Easytrieve are all programming languages used on mainframe systems. CICS (Customer Information Control System) is a transaction processing system/middleware, not a programming language. It's an environment that runs programs written in languages like COBOL.
-
Convert.ToString() handle null values but ToString() don't
-
ToString() output as per format supplied
-
Convert.ToString() only handle null values
-
ToString() handle null values but Convert.ToString() don't
A
Correct answer
Explanation
The critical difference is null handling: calling ToString() on a null reference throws NullReferenceException, while Convert.ToString(null) returns null without throwing. Convert.ToString() also handles various type conversions via IConvertible, while ToString() is the instance method for string representation.
-
StringBuilder is more efficient when there is a large amount of string manipulation
-
Strings are immutable, so each time a string is changed, a new instance in memory is created.
-
StringBuilder is mutable; when you modify an instance of the StringBuilder class, you modify the actual string, not a copy
-
Strings are mutable in .Net
D
Correct answer
Explanation
System.String is immutable - every operation creates a new string object in memory. StringBuilder is mutable - modifications happen in-place on the same instance. Therefore, the statement "Strings are mutable in .Net" is false, making D the correct choice for the incorrect statement. Options A, B, and C all describe actual differences correctly.
-
HashTable
-
ArrayList
-
SortedList
-
All of above
A
Correct answer
Explanation
HashTable (and its generic version Dictionary) is designed specifically for key-value access where each key must be unique. ArrayList and SortedList store elements without requiring unique keys - ArrayList is a dynamic array and SortedList maintains sorted order but allows duplicates.
-
Declare as null
-
Declare as Null and Call the dispose method
-
Call GC.SupressFinalize method for the object
-
None of the above
B
Correct answer
Explanation
For objects that are no longer needed and implement IDisposable, you should set the reference to null AND call the Dispose() method to release unmanaged resources promptly. Setting to null helps the garbage collector by removing the reference, while Dispose releases resources like file handles or database connections immediately rather than waiting for finalization.
-
if(stringValue == null)
-
if(string.IsNullOrEmpty(stringValue))
-
if(stringValue == DbNull.value)
-
None of the above
C
Correct answer
Explanation
When checking database values stored in an ADO.NET DataSet, missing database values are represented by DBNull.Value, not C# null. Thus, comparing the value to DBNull.Value is correct. Note that the option text contains a typo 'DbNull.value' instead of 'DBNull.Value', but it represents the correct concept.
-
It does not cover all the functions as covered by System.Net.Mail
-
It is obsolete as compared to System.Net.Mail
-
It is not secure way of sending mails.
-
None of the above
B
Correct answer
Explanation
System.Web.Mail is marked as obsolete and deprecated by Microsoft. It was replaced by System.Net.Mail which provides better functionality, security, and maintainability. Using obsolete classes is discouraged as they may be removed in future versions and often lack modern features. System.Net.Mail became the standard starting with .NET Framework 2.0.
-
<&>...</&>
-
<?php>...</?>
-
<?php…?>
-
<script>...</script>
C
Correct answer
Explanation
PHP scripts must be enclosed in delimiters. Option B incorrectly uses as the opening tag, while option A is not valid PHP syntax. The correct opening tag is as the closing tag.
-
printf("Hello World")
-
echo "Hello World";
-
"Hello World";
-
Document.write("Hello World");
B
Correct answer
Explanation
echo is the correct way to output text in PHP. While printf also works for formatted output, echo is the standard method for simple string output and is the most commonly used. Option C is just a string literal without an output command, and option D uses JavaScript syntax.