Ejemplo 1: variables globales y locales en c
#include <stdio.h> //local parameters take precedance to global//
/* global variable declaration */
int a = 20;
int main () {
/* local variable declaration in main function */
int a = 10;
int b = 20;
int c = 0;
printf ("value of a in main() = %dn", a);
c = sum( a, b);
printf ("value of c in main() = %dn", c);
return 0;
}
/* function to add two integers */
int sum(int a, int b) {
printf ("value of a in sum() = %dn", a);
printf ("value of b in sum() = %dn", b);
return a + b;
}
Ejemplo 2: Cómo definir variables globales
Use pm.globals to define a global variable:
pm.globals.set("variable_key", "variable_value");
Ejemplo 3: variable globlal c
#include <stdio.h>
/* global variable declaration */
int g;
int main () {
/* local variable declaration */
int a, b;
/* actual initialization */
a = 10;
b = 20;
g = a + b;
printf ("value of a = %d, b = %d and g = %dn", a, b, g);
return 0;
}
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)