Please check the below program.
#include <stdio.h>
struct st
{
int a ;
}
fn ()
{
struct st obj ;
obj.a = 10 ;
return obj ;
}
int main()
{
struct st obj = fn() ;
printf ("%d", obj.a) ;
}
Following are the questions
What is the output of the program?
Where is ';' terminating the declaration of 'struct st'?
By ISO IE...
this has interested me purely as research and personal development. i have a namespaced set of functions / variables.
within 1 function I need to call another through setTimeout but keeping the scope to 'this'. i am struggling with this a little, can't seem to bind it for when the setTimeout runs.
var foo = {
ads: ["foo","bar"],
...
I'm wondering if anyone if aware of a language that has support for variables (that could be considered 'global'), and subroutines (functions), but without a concept of parameter passing, local scope, etc. Something where every subroutine has access to every global variable, and only global variables.
...
I learnt that
the type specifier that declares the
identifier in the list of parameter
declarations in a function prototype
(not part of a function definition),
the identifier has function prototype
scope, which terminates at the end of
the function declarator.
Please see the C program mentioned below.
void fn (struct...
I desperately need some help on this one.
I've created a <script> that closely parallels, and reproduces the problem of, another more complex <script> that I've written elsewhere.
Here's what it does:
creates an <iframe> and inserts in into a <div> on the page
creates and appends a document to that <iframe>, which contains a <script>...
Why is the expression specified inside a comma operator (such as the example below) not considered a constant expression?
For example,
int a = (10,20) ;
when given in global scope yields an error "initializer is not a constant", though both the expressions separated by a comma operator are constants (constant expressions). Why is th...
I try to keep things as local as possible, so I put enums at class scope, even if they are shared between two classes (I put it in the class that "goes better" with it.) This has worked out great, but I recently ran into an issue where a circular dependency will occur if I put the enum at class scope.
The enum is going to be a construct...
This may be more of a scoping question. I'm trying to set a JSON object within a $.getJSON function, but I need to be able to use that object outside of the callback.
var jsonIssues = {}; // declare json variable
$.getJSON("url", function(data) {
jsonIssues = data.Issues;
});
// jsonIssues not accessible here
A similar question...
Take below code iterates over 6 input buttons and attaches an onclick event to every button that alerts the index number of the respective iteration:
for (var i = 1; i < 6; ++i) {
var but = document.getElementById('b_' + i);
(function (el) {
var num = i;
but.onclick = function () {
alert(num);
...
Does singleton/session scopes of Spring beans require that access to all its fields must be synchronized? Say through "synchronized" keyword or using some classes from package "java.util.concurrent".
As example, is this code not thread safe? (copy/pased from here):
@Component
@SessionScoped
public class ShoppingCart {
private List<...
Is there such a thing as local, private, static and public variables in PHP? If so, can you give samples of each and how their scope is demonstrated inside and outside the class and inside functions?
...
I didn't know you could do this:
def tom():
print "tom's locals: ", locals()
def dick(z):
print "z.__name__ = ", z.__name__
z.guest = "Harry"
print "z.guest = ", z.guest
print "dick's locals: ", locals()
tom() #>>> tom's locals: {}
#print tom.guest #AttributeError: 'function' object has no attribut...
I'm writing an online game which allows a user to progress from one puzzle to the next, and if the user makes mistakes, each puzzle has a start again button to allow the user to start just that puzzle from scratch. A simplified version of the code's structure is below:
function puzzle(generator) {
this.init = function() {
t...
Im trying to understand scope in nested classes in python. Here is my example code :
class OuterClass:
outer_var = 1
class InnerClass:
inner_var = outer_var
The creation of class does not complete and I get the error :
<type 'exceptions.NameError'>: name 'outer_var' is not defined
trying inner_var = Outerclass...
Hi,
I am trying to create a macro that takes a scope as a parameter.
I know, it is probably not a good thing etc etc.
I was trying this and got the problem that preprocessor looks for commas and parentheses... the problem is with enum.
How would I declare a enum inside a scope that is a parameter of a macro?
when the compiler see ...
Is there a way to declare a variable so it is available in all functions. Basically I want to call: Global $varName; automatically for every function. And no, I can't use a constant.
I don't think its possible but wanted to ask anyway. Thanks! :D
...
My question is really more about scope in JavaScript, rather then closures.
Let's take the following code:
var f = function () {
var n = 0;
return function () {
return n++;
};
}();
console.log(f());
console.log(f());
The above code outputs:
0
1
As you can see from the above code, f (self-invoked) returns a function, creating...
Hello all,
I'm trying to group some exisiting top-level functions inside a
closure (to avoid polluting the global namespace) but I'm not quite
getting it to work.
First, all the JS works outside my anonymous function, but once I put
it in the anonymous function I get an error of "crossfade is not
defined". Does anyone see anything comp...
I'm using the friendly_id gem. I also have my routes nested:
# config/routes.rb
map.resources :users do |user|
user.resources :events
end
So I have URLs like /users/nfm/events/birthday-2009.
In my models, I want the event title to be scoped to the username, so that both nfm and mrmagoo can have events birthday-2009 without them bei...
Is the static keyword in C used only for limiting the scope of a variable to a single file?
I need to know if I understood this right. Please assume the following 3 files,
file1.c
int a;
file2.c
int b;
file3.c
static int c;
Now, if the 3 files are compiled together, then the variables "a" & "b" should have a global scope and ...