Search
 
SCRIPT & CODE EXAMPLE
 

CPP

Return multiple values from a function using pointers

#include <iostream>

using namespace std; 

void maxAndMin(int num[], int size, int* max, int* min){
    for(int i = 0; i < size; i++){
    if(num[i] < *min)
        *min = num[i];
    if(num[i] > *max)
        *max = num[i];
    }
    cout << "Minimum number is: "<< *min << endl;
    cout << "Maximum number is: "<< *max << endl;
}

int main(){
    int numbers[5];
    for (int i = 0 ; i < 5 ; i++){
        cout << "Number: ";
        cin >> numbers[i];
    }
    int min = numbers[0];
    int max = numbers[0];
    maxAndMin(numbers, 5, &max, &min);
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: string to char array c++ 
Cpp :: add on screen debug message ue4 
Cpp :: calculate how many liters would be needed 
Cpp :: print 5 table in c++ 
Cpp :: c++ rand() 
Cpp :: c++ read file to char buffer 
Cpp :: C++ Converting Kelvin to Fahrenheit 
Cpp :: c++ Modulo 10^9+7 (1000000007) 
Cpp :: vector of structs c++ 
Cpp :: n queens c++ 
Cpp :: finding size of columns and rows in 2d vector c++ 
Cpp :: how to display a variable in c++ 
Cpp :: quadratic problem solution c++ 
Cpp :: convert string to stream c++ 
Cpp :: save all output in log file c cpp 
Cpp :: OPA in expanse 
Cpp :: 2d vector c++ declaration 
Cpp :: c++ unordered_map check if key exists 
Cpp :: c++ memory leak 
Cpp :: how to use string variable in switch case in c++ 
Cpp :: round double to n decimal places c++ 
Cpp :: delete map elements while iterating cpp 
Cpp :: how to make a random number in c++ 
Cpp :: check if file is empty c++ 
Cpp :: how to get size of char array in c++ 
Cpp :: const char to string 
Cpp :: c++ arithmetic operators 
Cpp :: c++ 
Cpp :: change int to string c++ 
Cpp :: update variable in const function C++ 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =