variables interview questions
Top variables frequently asked interview questions
In another question I posted someone told me that there is a difference between:
@variable
and:
variable
in MySQL. He also mentioned how MSSQL has batch scope and MySQL has session scope. Can someone elaborate on this for me?
Source: (StackOverflow)
I've got a script 'myscript' that outputs the following:
abc
def
ghi
in another script, I call:
declare RESULT=$(./myscript)
and $RESULT
gets the value
abc def ghi
Is there a way to store the result either with the newlines, or with '\n' character so I can output it with 'echo -e
'?
Source: (StackOverflow)
What is the meaning of _
after for
in this code?
if tbh.bag:
n = 0
for _ in tbh.bag.atom_set():
n += 1
Source: (StackOverflow)
In LaTeX, how can I define a string variable whose content is used instead of the variable in the compiled PDF?
Let's say I'm writing a tech doc on a software and I want to define the package name in the preamble or somewhere so that if its name changes, I don't have to replace it in a lot of places but only in one place.
Source: (StackOverflow)
This question already has an answer here:
I would like to check whether a variable is either an array or a single value in JavaScript.
I have found a possible solution...
if (variable.constructor == Array)...
Is this the best way this can be done?
Source: (StackOverflow)
I want to toggle a variable between 0 and 1. If it's 0 I want to set it to 1, else if it's 1 I want to set it to 0.
This is such a fundamental operation that I write so often I'd like to investigate the shortest, clearest possible way of doing it. Here's my best so far:
v = (v == 0 ? 1 : 0);
Can you improve on this?
Edit: the question is asking how to write the above statement in the fewest characters while retaining clarity - how is this 'not a real question'? This wasn't intended to be a code-golf exercise, though some interesting answers have come out of people approaching it as golf - it's nice to see golf being used in a constructive and thought-provoking manner.
Source: (StackOverflow)
I have a shell script with this code:
var=`hg st -R "$path"`
if [ -n "$var" ]; then
echo $var
fi
But the conditional code always executes, because hg st
always prints at least one newline character.
- Is there a simple way to strip whitespace from
$var
(like trim()
in PHP)?
or
- Is there a standard way of dealing with this issue?
I could use sed or AWK, but I'd like to think there is a more elegant solution to this problem.
Source: (StackOverflow)
I'm currently using the iOS 5 SDK trying to develop my app.
I'm trying to make an NSString a property, and then to synthesize it in the .m file (I have done this before with no issues). Now, I came across this: "Semantic Issue: Property's synthesized getter follows Cocoa naming convention for returning 'owned' objects."
This is my code:
.h
@interface ViewController : UIViewController {
NSString *newTitle;
}
@property (strong, nonatomic) NSString *newTitle;
.m
@synthesize newTitle;
Does anyone have a clue how I could fix this?
Thanks!!
Source: (StackOverflow)
Earlier I asked a question about why I see so many examples use the var
keyword and got the answer that while it is only necessary for anonymous types, that it is used nonetheless to make writing code 'quicker'/easier and 'just because'.
Following this link ("C# 3.0 - Var Isn't Objec") I saw that var
gets compiled down to the correct type in the IL (you will see it about midway down article).
My question is how much more, if any, IL code does using the var
keyword take, and would it be even close to having a measurable level on the performance of the code if it was used everywhere?
Source: (StackOverflow)
I've seen in a few iPhone examples that attributes have used an underscore _ in front of the variable. Does anyone know what this means? or how it works?
an interface file I'm using looks like:
@interface MissionCell : UITableViewCell {
Mission *_mission;
UILabel *_missionName;
}
@property (nonatomic, retain) UILabel *missionName;
- (Mission *)mission;
I'm not sure exactly what the above does but when I try to set the mission name like:
aMission.missionName = missionName;
I get the error: request for member 'missionName' in something not a structure or union
Source: (StackOverflow)
Is there a way to check if the type of a variable in python is string.. like
isinstance(x,int);
for integer values?
Source: (StackOverflow)
Which method of checking if a variable has been initialized is better/correct?
(Assuming the variable could hold anything (string, int, object, function, etc.))
if (elem) { // or !elem
or
if (typeof(elem) !== 'undefined') {
or
if (elem != null) {
Source: (StackOverflow)