Computer Knowledge

Programming Fundamentals

2,381 Questions

Programming fundamentals form the core logic of software development and computer science. This includes variable declarations, pointer assignments, loop iterations, and exception handling. These technical topics are regularly tested in computer knowledge and IT officer competitive examinations.

Variables and arraysPointer assignmentsLoop iterationsException handling blocksCompile time errorsFunction references

Programming Fundamentals Questions

Multiple choice html
  1. True

  2. False

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

The default case in a switch statement only executes when NO other case matches the expression being evaluated. It's an optional catch-all that runs if the switch value doesn't equal any of the defined case values. If a case matches and executes (with or without a break), the default is skipped.

Multiple choice javascript
  1. call function myFunction

  2. myFunction()

  3. call myFunction()

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

To call a function named "myFunction", the user needs to use the following syntax:

myFunction();

Option A is incorrect because it is not the correct syntax for calling a function.

Option B is the correct answer because it calls the function "myFunction" using the proper syntax.

Option C is incorrect because it includes the word "call", which is not necessary when calling a function in most programming languages.

Therefore, the answer is: B. myFunction()

Multiple choice javascript
  1. Math.max(6,8)

  2. top(6,8)

  3. ceil(6,8)

  4. Math.ceil(6,8)

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

The Math.max() method returns the largest number from a list of arguments. Option A correctly uses Math.max(6,8) to find the larger value. ceil() rounds up to the next integer, it doesn't compare values, and there's no top() method in JavaScript.

Multiple choice javascript
  1. var myarray = new Array();

  2. var myarray = array new;

  3. var new Array() = myarray;

  4. var new array = myarray;

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

Arrays in JavaScript are created using the Array constructor with 'new' keyword. Option A shows the correct syntax: new Array(). Options B, C, and D incorrectly place keywords and variable names in the wrong order - they mix up the constructor name with the variable name.

Multiple choice javascript
  1. A method

  2. A function

  3. An operator

  4. A statement

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

Void is an operator in JavaScript, not a method, function, or statement. It evaluates an expression and returns undefined. Option C is correct. Options A, B, and D incorrectly classify void as a method, function, or statement respectively.

Multiple choice javascript
  1. setTimeout("a["+i+"]",1000)

  2. k = a & i

  3. k = a(i)

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

Option A demonstrates array syntax using bracket notation a[i] within setTimeout. Options B and C use incorrect syntax - the & operator is bitwise AND, not array access, and a(i) uses function call syntax instead of array indexing. Only option A properly uses JavaScript array notation.

Multiple choice javascript
  1. Conservation of client CPU resources

  2. Increased validity of form submission

  3. Conservation of bandwidth

  4. Increase end-user satisfaction

  5. Either BCD

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

JavaScript form validation provides multiple benefits: it increases validity by catching errors before submission (B), conserves bandwidth by reducing server round-trips for invalid data (C), and increases user satisfaction by providing immediate feedback (D). Option E correctly identifies all these advantages. Option A is incorrect because client-side validation uses client CPU resources, it doesn't conserve them.

Multiple choice javascript
  1. When you have multiple statements on multiple lines

  2. When you have multiple statements on a line

  3. When you have single statement on multiple lines

  4. When you have single statement on a line

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

In many programming languages like C, Java, and JavaScript, semicolons act as statement terminators. While they often end lines, their primary structural necessity occurs when placing multiple distinct statements on a single line to help the compiler or interpreter distinguish between them.

Multiple choice perl
  1. True

  2. False

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

In Perl documentation and community usage, the terms 'function' and 'subroutine' (often shortened to 'sub') are used interchangeably to describe a named block of code that performs a specific task. While some languages distinguish between them based on return values, Perl does not.

Multiple choice php
  1. gettype()

  2. is_double()

  3. get_type()

  4. is_date()

  5. A&B

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

The gettype() function returns the type of a variable as a string (e.g., 'integer', 'string', 'array'). The is_*() family of functions like is_double(), is_int(), is_string() check if a variable is of a specific type, returning boolean true/false. Note that is_double() is an alias for is_float() - both check for floating-point numbers.

Multiple choice php
  1. ;

  2. #

  3. !

  4. %>

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

PHP instructions (statements) must be terminated with a semicolon (;), similar to many other programming languages like C, Java, and JavaScript. The semicolon tells the parser where the statement ends. This is required syntax in PHP - forgetting semicolons is a common syntax error.

Multiple choice php
  1. function myFunction()

  2. new_function myFunction()

  3. create myFunction()

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

PHP uses the function keyword to declare a user-defined function, followed by the function name and parentheses. Keywords like new_function or create are not valid PHP syntax for declaring functions. This follows standard C-style and scripting language conventions used in PHP.

Multiple choice php
  1. $my-Var
  2. $myVar
  3. $my_Var
Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

To determine which variable has an illegal name, we need to understand the rules for variable naming conventions.

In most programming languages, variables can be named using letters, numbers, and underscores. However, there are some restrictions:

  1. The variable name cannot start with a number.
  2. The variable name cannot contain spaces or special characters, except for underscores.

Now let's analyze each option:

A. $my-Var: This variable name uses a hyphen (-) between "my" and "Var". Hyphens are not allowed in variable names in most programming languages, so option A has an illegal name.

B. $myVar: This variable name uses only letters and does not contain any illegal characters. Option B has a legal name.

C. $my_Var: This variable name uses an underscore (_) between "my" and "Var". Underscores are commonly used in variable names and are allowed in most programming languages. Option C has a legal name.

Therefore, the variable with the illegal name is:

The Answer is: A. $my-Var