0

If there any way to make x = 2 when i call the second f(arr)

#include<iostream> using namespace std; void f(int arr[]) { int x = 0; cout << arr[x]; x++; } int main() { int arr[4] = { 1, 2, 3, 4 }; f(arr); f(arr); }

30th Oct 2019, 5:10 PM
Abdelrhman Albarbary
Abdelrhman Albarbary - avatar
7 odpowiedzi
+ 5
Yes, just add the keyword "static" static int x = 0;
30th Oct 2019, 5:17 PM
Matthias
Matthias - avatar
+ 1
Thank you man You are amazing👍
30th Oct 2019, 7:12 PM
Abdelrhman Albarbary
Abdelrhman Albarbary - avatar
0
Thanks
30th Oct 2019, 6:54 PM
Abdelrhman Albarbary
Abdelrhman Albarbary - avatar
0
I can make it global too
30th Oct 2019, 6:54 PM
Abdelrhman Albarbary
Abdelrhman Albarbary - avatar