This thing is giving me error. C Language -
how can fix this? want scanf()
value d, how can it? need please. appreciate that.
#include <stdio.h> #include <stdlib.h> void lerdeputados(int d) { printf("indique o nĂºmero de deputados repartir: "); scanf("%d",&d); } int main(void) { int d; lerdeputados(d); printf("%d",d); return 0; }
the problem here when pass variable d
lerdeputados
function, it's passed by value, means copied. value changed inside function, it's changing copy, , changing copy of course not change original.
what need here pass variable by reference. unfortunately c doesn't have that, can emulated using pointer. in other words, need pass pointer variable d
lerdeputados
function.
like
void lerdeputados(int *d) { ... }
then call address-of operator:
lerdeputados(&d);
Comments
Post a Comment