jueves, 1 de septiembre de 2011

Ejemplo punteros en funciones

Ejemplo punteros en funciones en lenguaje C

Enlace CodePad
http://codepad.org/z5oCbj27

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Código Fuente
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

#include <stdio.h>
#include <stdlib.h>


void funcion_sin_punteros (int a);
void funcion_con_punteros (int * a);

int main()
{
    int dato_1 = 0;
    int dato_2 = 0;

    //llamada a funcion pasando parametros por valor
    funcion_sin_punteros (dato_1);

    printf("\nEl valor de dato_1 tras llamar a funcion_sin_punteros es %d", dato_1);

    //llamada a funcion pasando parametros por referencia mediante punteros
    funcion_con_punteros (&dato_2);

    printf("\nEl valor de dato_2 tras llamar a funcion_con_punteros es %d", dato_2);

    return 0;
}

void funcion_sin_punteros (int a)
{
    a = a + 1;
}

void funcion_con_punteros (int * a)
{
    *a = *a + 1;
}

2 comentarios:

Related Posts Plugin for WordPress, Blogger...