Difference in passing of data type by reference

Asked

Viewed 18 times

0

Hello, I’m having doubts about how to pass determined by reference.

Follow the code below:

#include <stdio.h>
#include <string.h>

mostra_frase(char *frase){
    printf("\nFrase digitada %s\n", frase);
}

void mostra_numero (int *numero){
    printf("Numero digitado %i", *numero);
}

int main(){
    char frase[100];
    int numero;

    printf("Digite uma frase\n");
    gets(frase);

    printf("Digite um numero\n");
    scanf("%i", &numero);

    mostra_frase(frase);
    mostra_numero(&numero);     
}

My question is: Why in the passage by reference of the phrase using gets do not need to pass the memory &address and in passing a number yes ?

  • Because the name of an array actually refers to the address of the first element of that array.

  • The pointer in mostra_numero() is completely unnecessary. gets(0 should not be used anymore.

No answers

Browser other questions tagged

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