简体   繁体   中英

Function in c that increments a variable

I want to develop a function which increments in 1 any variable that you pass by argument. I did this, but I know it's wrong:

#include <stdio.h> 

int incremento(int);

int main(int argc, char** argv){
    int x = 1;
    printf("%d", x);
    incremento(x);
    printf("%d", x);

    return 0; 
}

int incremento(int n){
    n++;
    return n; 
}

Thanks

#include <stdio.h> 

void incremento(int *);

int main(int argc, char** argv){
  int x = 1;
  printf("%d", x);
  incremento(&x);
  printf("%d", x);

  return 0; 
 }

void incremento(int *n){
  (*n)++;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM