|
|
![]() |
| Thread Tools | Search this Thread |
#1
| |||
| |||
Accessing a variable outside a function without arg I have a variable declared in main () and function according to finally use a arg_fonction (): Code: int main () ( int variable = 23; function (& variable); getchar (); return 0; ) void function (int * variable) ( arg_fonction (variable); ) arg_fonction void (int * variable) ( printf ( "% d \ n", * variable); * Variable = 42; ) |
#2
| |||
| |||
Re: Accessing a variable outside a function without arg What you want to do is called a global variable, use with moderation ... To make a global variable, it is sufficient for you to declare it outside your function : Code: arg_var int = 42; int main (void) ( printf ( "% d \ n", arg_var); return 0; ) |
#3
| |||
| |||
Re: Accessing a variable outside a function without arg Have you tried with varying types of extern? Code: var j; $.getJSON("url", function (json) { // update iji = json.var; }); |
#4
| |||
| |||
Re: Accessing a variable outside a function without arg try this example : main.c Code: # include <stdio.h> # include <stdlib.h> # include <string.h> # include "global.h" int main (void) ( printf ( "foo =% i \ n", foo); foo = 2; printf ( "foo =% i \ n", foo); return 0; ) Code: # indef global_header # define global_header # indef GLOBAL_PRIVATE extern int foo; # else int foo = 123; # endif # endif |
![]() |
|
Tags: c language, function, main, printf, variable |
Thread Tools | Search this Thread |
|
![]() | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Call a function depending on the variable name | Captain Carrot | Software Development | 5 | 23-03-2010 09:27 AM |
How to pass PHP variable value to jquery function? | Kasper | Software Development | 5 | 03-03-2010 06:41 PM |
Function with a variable number of arguments | Chrisch | Software Development | 3 | 20-11-2009 02:03 PM |
If variable is not initialized in main function | Jaisudha | Software Development | 3 | 18-11-2009 02:13 PM |
How to Call a variable subroutine or function | Sayam | Software Development | 2 | 16-04-2009 09:33 PM |