Cpp - Write program to pass more than one value of a function using pointer

Requirements

Write program to pass more than one value of a function using pointer

Demo

#include <iostream> 
   //  w  ww . jav a  2s.c  o  m
short factor(int, int*, int*); 
 
int main() 
{ 
    int number = 10, squared, cubed; 
    short error; 
 
    error = factor(number, &squared, &cubed); 
 
    if (!error) 
    { 
             std::cout << "number: " << number << "\n"; 
             std::cout << "square: " << squared << "\n"; 
             std::cout << "cubed: "  << cubed   << "\n"; 
    } 
    else 
        std::cout << "Error encountered!!\n"; 
    return 0; 
} 
 
short factor(int n, int *pSquared, int *pCubed) 
{ 
    short value = 0; 
    if (n > 20) 
    { 
        value = 1; 
    } 
    else 
    { 
        *pSquared = n*n; 
        *pCubed = n*n*n; 
        value = 0; 
    } 
    return value; 
}

Result

Related Exercise