Computer Knowledge

Programming Fundamentals

2,611 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 technology web technology
  1. are different how they handle failure

  2. both are same in every aspects

  3. is include() produced a Fatal Error while require results in a Warning

  4. none of above

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

include() produces a warning and continues script execution if the file is not found, while require() causes a fatal error and stops the script. This is their fundamental difference in failure handling. Option B is incorrect because they are not the same. Option C has the error types reversed.

Multiple choice technology web technology
  1. Any variable available at that line in the calling file will be available within the called file from that point

  2. Any variable available at that line in the calling file will not be available within the called file

  3. Variables are local in both called and calling files

  4. None of above

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

When a file is included in PHP, it inherits the variable scope from the line where the include statement appears. Any variables available at that point in the calling file become accessible to the included code. Option B is false because variables are shared, not isolated. Option C is false because scope is inherited, not local.

Multiple choice technology web technology
  1. Enable or disable cookie support

  2. Declare cookie variables

  3. Store data in cookie variable

  4. All of above

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

setcookie() is used to send a cookie to the browser, storing data in a cookie variable. Option A is incorrect because it doesn't enable/disable cookie support - that's a browser/php.ini setting. Option B is wrong because it doesn't just declare variables - it actually sets cookie values. Option D is too broad.

Multiple choice technology web technology
  1. sssion_decode

  2. session_destroy

  3. session_id

  4. session_pw

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

PHP has session functions like session_decode(), session_destroy(), and session_id(). However, session_pw() is NOT a valid PHP session function - it doesn't exist. Options A, B, and C are all real PHP session functions (despite the typo 'sssion_decode'). Option D is correct because session_pw() doesn't exist.

Multiple choice technology web technology
  1. <?echo "This is php example"; ?>

  2. <P="This is php example"; ?>

  3. <?PHP echo "This is php example"; php?>

  4. <script language="php"> print "This is php example";</script>

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

This question asks which statement is DIFFERENT. Options A, B, and D are valid PHP output statements that would print 'This is php example'. Option C has 'php?>' instead of '?>' at the end, making it a syntax error that would fail to execute, thus producing different output (an error) compared to the others.

Multiple choice technology web technology
  1. echo ( )

  2. print ( )

  3. Print f ( )

  4. None of above

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

printf() is designed for outputting formatted strings with placeholders for variables, making it ideal for blending static text with dynamic variable values. While echo can handle this with concatenation or double quotes, printf provides cleaner formatting syntax with type specifiers like %s for strings, %d for integers.

Multiple choice technology web technology
  1. echo ( )

  2. print ( )

  3. print f ( )

  4. s print f ( )

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

echo() and print() output directly. printf() formats and outputs directly. Only sprintf() (string printf) assigns the formatted output to a string variable instead of displaying it. This makes sprintf() the correct choice for capturing formatted output in a variable.

Multiple choice technology performance
  1. For (i = 0; i < 10; i--)

  2. For (i = 1; i < 10; i--)

  3. For (i = 1; i < 10; i++)

  4. For (i = 1; i <= 10; i++)

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

A for loop that executes 10 times requires starting at 1, continuing while i is less than or equal to 10, and incrementing i each iteration. Option A and B use i-- which would decrement, causing infinite loops. Option C only runs 9 times (i from 1 to 9). Option D correctly runs from i=1 to i=10 inclusive.