Danger signal on a var in C

Asked

Viewed 47 times

-4

The program and the recursiveness are correct, but even so, a danger signal occurs.

#include <stdio.h>

void ant_suc (int num){
    int ant = num - 1;
    int suc = num + 1;

    return printf("O numero antecessor a %d eh %d e seu sucessor eh %d", num, ant, suc);
}

int main(void){
    int num;
    printf("Informe um numero inteiro: ");
    scanf("%d", &num);
    ant_suc(num);
    return 0;
}

1 answer

1


You are using printf as the return of the ant_suc function, which has been defined as void type and does not expect return of any kind.

Declaring the ant_suc function of the form below should solve the Warning problem, and be the correct way to treat void type function:

void ant_suc (int num){
    int ant = num - 1;
    int suc = num + 1;
    printf("O numero antecessor a %d eh %d e seu sucessor eh %d", num, ant, suc);
    return;
 }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.