Can the parameters of the C/C++ function be used without initialization?

Asked 2 years ago, Updated 2 years ago, 56 views

#include <iostream> 
using namespace std;

int getsum(int);
int main() {

  int num, sum;
  cin >> num;
  sum = getsum(num);

  cout << "sum " << sum << endl;

}

int   getsum(int value) {
  int sum = 0;

  sum += value;
  return sum;
}



In this code, the variable value is declared in the function getsum, but the value has not been initialized to any value, so can I write a code called sum+=value?

c c++ function

2022-09-20 19:53

1 Answers

The value is a parameter that receives the factor num, so it receives the value of num. For example, if you put 1 in num and getsum(num), the value is 1.


2022-09-20 19:53

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.