samedi 12 septembre 2020

what is address of local variable 'a' returned?

  1. I don't know what is wrong.
  2. It tells address of local variable returned.
#include<iostream>
using namespace std;
int *myfunc(int *ptrB);

int main(){
    int *a, b;
    cout << "give b :" << endl;
    cin >> b;
    a = myfunc(&b);
    cout << "a is :" << *a << endl;
    return 0;
}

int *myfunc(int *ptrB) {
    int a; 
    a= (*ptrB) * (*ptrB);
    *ptrB = a;
    return &a;
}

Aucun commentaire:

Enregistrer un commentaire