EzDevInfo.com

syntax interview questions

Top syntax frequently asked interview questions

What does "static" mean in a C program?

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)

Python integer incrementing with ++ [duplicate]

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)

Advertisements

What is the difference between single-quoted and double-quoted strings in PHP?

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)

Haskell: difference between . (dot) and $ (dollar sign)

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)

Comments in Markdown

What is the syntax for storing a comment in a markdown file, e.g. a CVS $Id$ comment at the top of the file? I found nothing on the markdown project.


Source: (StackOverflow)

How can I do a line break (line continuation) in Python?

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)

Why does ++[[]][+[]]+[+[]] return the string "10"?

This is valid and returns the string "10" in JavaScript (more examples here):

++[[]][+[]]+[+[]]

Why? What is happening here?


Source: (StackOverflow)

What does ** (double star) and * (star) do for Python parameters?

In the following method calls, what does the * and ** do for param2?

def foo(param1, *param2):
def bar(param1, **param2):

Source: (StackOverflow)

How do I convert a float Number to a whole Number in Javascript?

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)

How do you comment out code in PowerShell?

How do you comment out code in PowerShell (1.0 or 2.0)?


Source: (StackOverflow)

Java method with return type compiles without return statement

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)

How do you printf an unsigned long long int(the format specifier for unsigned long long int)?

#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)

What does "use strict" do in JavaScript, and what is the reasoning behind it?

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)

var functionName = function() {} vs function functionName() {}

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)

Are self-closing tags valid in HTML5?

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)