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
-
are different how they handle failure
-
both are same in every aspects
-
is include() produced a Fatal Error while require results in a Warning
-
none of above
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.
-
Any variable available at that line in the calling file will be available within the called file from that point
-
Any variable available at that line in the calling file will not be available within the called file
-
Variables are local in both called and calling files
-
None of above
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.
-
Enable or disable cookie support
-
Declare cookie variables
-
Store data in cookie variable
-
All of above
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.
-
sssion_decode
-
session_destroy
-
session_id
-
session_pw
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.
-
<?echo "This is php example"; ?>
-
<P="This is php example"; ?>
-
<?PHP echo "This is php example"; php?>
-
<script language="php"> print "This is php example";</script>
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.
-
Single line c++ syntax - //
-
Shell syntax - #
-
Both of above
-
None of above
C
Correct answer
Explanation
PHP supports both C++ single-line comments starting with // and shell/Perl style single-line comments starting with #. Thus, both commenting styles are supported.
-
echo ( )
-
print ( )
-
both
-
None
B
Correct answer
Explanation
print() returns 1 when output is successful, making it usable in expressions. echo() outputs content but returns void (no value). This makes print() unique among PHP output functions in having a return value indicating success.
-
echo ( )
-
print ( )
-
Print f ( )
-
None of above
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.
A
Correct answer
Explanation
In printf(), %b is for binary, %c for character, %d for decimal integer. %a is not a valid printf type specifier in PHP - valid format specifiers include %b, %c, %d, %e, %f, %o, %s, %u, %x, %X, and others, but not %a.
-
echo ( )
-
print ( )
-
print f ( )
-
s print f ( )
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.
-
Integer
-
Float
-
String
-
Booleans
C
Correct answer
Explanation
Strings can be treated as arrays in PHP using array syntax, accessing individual characters by index (e.g., $str[0]).
-
(array)
-
(int64)
-
(real) or (double) or (float)
-
(object)
B
Correct answer
Explanation
PHP 6 introduced the (int64) casting operator for explicit 64-bit integer conversion, complementing existing type casts.
-
my-function
-
size
-
–some word
-
This&that
-
Local
-
function parameter
-
static
-
None of above
C
Correct answer
Explanation
Static variables retain their values between function calls, unlike local variables which are reinitialized each time.
-
For (i = 0; i < 10; i--)
-
For (i = 1; i < 10; i--)
-
For (i = 1; i < 10; i++)
-
For (i = 1; i <= 10; i++)
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.