Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing structure to a function

Tags:

I was practicing different methods to assign values to the structure variables. But, when I tried this I am getting some garbage value. Here is the code.

#include<iostream>
using namespace std ;

struct Distance{
    int feet ;
    int inches;
};

void get_val(Distance );               
void disp(Distance);

int main(){

    Distance l, m ;                   //Objects 
    get_val(l);
    get_val(m);
    disp(l);
    disp(m);
    return 0  ;
}

void get_val(Distance length){
    cout<<"\nEnter Length "
        <<"\nFeet  : ";
    cin>>length.feet;
    cout<<"\nInches : ";
    cin>>length.inches;
}
void disp(Distance length){
    cout<<"\nLength : \n"
        <<"Feet : "<<length.feet
        <<"\nInches : "<<length.inches ;
}

Why am I getting garbage value as the Output ?