Difference between revisions of "Interview Questions"
From Hawk Wiki
(→Single or Double Quotes?) |
(→Object-oriented programming) |
||
Line 3: | Line 3: | ||
==Object-oriented programming== | ==Object-oriented programming== | ||
Check here [[Interview_Questions(OOP)]] | Check here [[Interview_Questions(OOP)]] | ||
+ | ==Algorithm Interview Problems== | ||
+ | [[Algorithm Problems]] | ||
+ | |||
==C/C++== | ==C/C++== | ||
===ArrayList Vs LinkedList=== | ===ArrayList Vs LinkedList=== |
Revision as of 23:50, 21 February 2012
Contents
Some Translation
n! Multiplicative
Object-oriented programming
Check here Interview_Questions(OOP)
Algorithm Interview Problems
C/C++
ArrayList Vs LinkedList
ArrayList: fast random access
slow at delete
memory fill up issue
LinkedList: slow random access
quick delete
no memory fill up issue
complex data structure
PHP
abstract class
Can not be Instantiable.(cannot become instant. Can only be inherited)
abstract class Fruit { private $color; abstract public function eat() public function setColor($c) { $this->color = $c; } }
Single or Double Quotes?
//Sometimes people use double quotes in PHP to avoid having to use the period to separate code. For example, you could write: $color='red'; echo "I have a $color shirt on today<br/>"; //Faster however is not always better. A better way to write this code would be: echo 'I have a ' .$color. ' shirt on today<br/>'; echo 'I have a $color shirt on today<br/>';
Output:
I have a red shirt on today I have a red shirt on today I have a $color shirt on today
Avoid Mysql Injection
$_POST['username'] = 'aidan'; $_POST['password'] = "' OR ''='"; $query = "SELECT * FROM users WHERE user='{$_POST['username']}' AND password='{$_POST['password']}'"; $passwd=mysql_real_escape_string($_POST['password']); $passwd1=addslashes($_POST['password']); echo $passwd."<br />"; echo $passwd1."<br />"; echo ($query);
Output
\' OR \'\'=\' \' OR \'\'=\' SELECT * FROM users WHERE user='aidan' AND password='' OR ''=''
This would allow anyone to log in without a valid password.
JavaScript
Closure.
<script> function say667() { // Local variable that ends up within closure var num = 666; //var sayAlert = function() { alert(num); } return function() { num++; alert(num); }; } var sayNumba = say667(); sayNumba(); sayNumba(); </script>
The example will keep var num in the memory. alert 667 and 668 on each call;