2020-11-30

Uninitialized local variable c4700

https://www.programiz.com/cpp-programming/structure-function

I'm learning how to pass structures to functions using the website above, I spent 2 hours of trying to figure out what was wrong with my program, I decided to copy and paste the code on the website to see if they did it correctly and the same error came up. If anyone could help it would be appreciated, there code below.

Warning C6001 Using uninitialized memory 'p'. Structure-Function C:\DEV\C++\Structure-Function\Structure-Function\main.cpp 18

Error C4700 uninitialized local variable 'p' used Structure-Function C:\DEV\C++\Structure-Function\Structure-Function\main.cpp 18

#include <iostream>
using namespace std;

struct Person {
    char name[50];
    int age;
    float salary;
};

Person getData(Person); 
void displayData(Person); 

int main()
{

    Person p;

    p = getData(p);   
    displayData(p);

    return 0;
}

Person getData(Person p) {

    cout << "Enter Full name: ";
    cin.get(p.name, 50);

    cout << "Enter age: ";
    cin >> p.age;

    cout << "Enter salary: ";
    cin >> p.salary;

    return p;
}

void displayData(Person p)
{
    cout << "\nDisplaying Information." << endl;
    cout << "Name: " << p.name << endl;
    cout <<"Age: " << p.age << endl;
    cout << "Salary: " << p.salary;
}


from Recent Questions - Stack Overflow https://ift.tt/36lTBZA
https://ift.tt/eA8V8J

No comments:

Post a Comment