syntax interview questions
Top syntax frequently asked interview questions
I've seen the word static
used in different places in C code; is this like a static function/class in C# (where the implementation is shared across objects)?
Source: (StackOverflow)
Possible Duplicate:
Python: Behaviour of increment and decrement operators
I've always laughed to myself when I've looked back at my VB6 days and thought, "What modern language doesn't allow incrementing with double plus signs?":
number++
To my surprise, I can't find anything about this in the Python docs. Must I really subject myself to number = number + 1
? Don't people use the ++/--
notation?
Source: (StackOverflow)
I'm not an expert in PHP programming, but I'm a little confused why I see some code in PHP with string placed in single quotes and sometimes in double quotes.
I just know in .NET, or C language, if it is in single quote, that means it is a character, not a string.
Source: (StackOverflow)
What is the difference between the dot (.)
and the dollar sign ($)
?. As I understand it, they are both syntactic sugar for not needing to use parentheses.
Source: (StackOverflow)
I have a long line of code that I want to break up among multiple lines. What do I use and what is the syntax?
For example, adding a bunch of strings,
e = 'a' + 'b' + 'c' + 'd'
and have it like this:
e = 'a' + 'b' +
'c' + 'd'
Source: (StackOverflow)
In the following method calls, what does the *
and **
do for param2
?
def foo(param1, *param2):
def bar(param1, **param2):
Source: (StackOverflow)
I'd like to convert a float to a whole number in Javascript. Actually, I'd like to know how to do BOTH of the standard conversions: by truncating and by rounding. And efficiently, not via converting to a string and parsing.
Source: (StackOverflow)
Question 1:
Why does the following code compile without having a return statement?
public int a()
{
while(true);
}
Notice: If I add return after the while then I get an Unreachable Code Error
.
Question 2:
On the other hand, why does the following code compile,
public int a()
{
while(0 == 0);
}
even though the following does not.
public int a(int b)
{
while(b == b);
}
Source: (StackOverflow)
#include <stdio.h>
int main() {
unsigned long long int num = 285212672; //FYI: fits in 29 bits
int normalInt = 5;
printf("My number is %d bytes wide and its value is %ul. A normal number is %d.\n", sizeof(num), num, normalInt);
return 0;
}
Output:
My number is 8 bytes wide and its value is 285212672l. A normal number is 0.
I assume this unexpected result is from printing the unsigned long long int
. How do you printf()
an unsigned long long int
?
Source: (StackOverflow)
Recently, I ran some of my JavaScript code through Crockford's JSLint, and it gave the following error:
Problem at line 1 character 1: Missing "use strict" statement.
Doing some searching, I realized that some people add "use strict";
into their JavaScript code. Once I added the statement, the error stopped appearing. Unfortunately, Google did not reveal much of the history behind this string statement. Certainly it must have something to do with how the JavaScript is interpreted by the browser, but I have no idea what the effect would be.
So what is "use strict";
all about, what does it imply, and is it still relevant?
Do any of the current browsers respond to the "use strict";
string or is it for future use?
Source: (StackOverflow)
I've recently started maintaining someone else's JavaScript code. I'm fixing bugs, adding features and also trying to tidy up the code and make it more consistent.
The previous developer uses two ways of declaring functions and I can't work out if there is a reason behind it or not.
The two ways are:
var functionOne = function() {
// Some code
};
function functionTwo() {
// Some code
}
What are the reasons for using these two different methods and what are the pros and cons of each? Is there anything that can be done with one method that can't be done with the other?
Source: (StackOverflow)
The W3C validator doesn't like self-closing tags (those that end with "/>
") on non void elements (those that may not ever contain any content). Are they still valid in HTML5?
Some examples of accepted void elements would be:
<br />
<img src="" />
<input type="text" name="username" />
Some examples of rejected non-void elements would be:
<div id="myDiv" />
<span id="mySpan" />
<textarea id="someTextMessage" />
Note: the W3C validator actually accepts void self-closing tags: the author originally had a problem because of a simple typo (\>
instead of />
). However, self-closing tags are not 100% valid in HTML5 in general, and the answers elaborate on the issue of self-closing tags across various HTML flavors.
Source: (StackOverflow)