int arr[] = {12, 34, 54, 2, 3}, i;
Happened to see an array declared this way, source here: https://www.geeksforgeeks.org/shellsort/
What does the ,ipart mean? It doesn't seem to do anything yet compiles.
int arr[] = {12, 34, 54, 2, 3}, i;
Happened to see an array declared this way, source here: https://www.geeksforgeeks.org/shellsort/
What does the ,ipart mean? It doesn't seem to do anything yet compiles.
This is the same as doing
int arr[] = {12, 34, 54, 2, 3};
int i;
You can declare and initialize more than one variable in a line, using ,. In this case arr is initialized with 12, 34, 54, 2, 3 and i is just declared, but not initialized.
The i part is a integer variable. Its same as declareing as separate follows where arr is initialised with 5 items and i is not initialised:
int arr[] = {12, 34, 54, 2, 3};
int i;
For more illustration if you compile the following code:
#include <iostream>
using namespace std;
int main()
{
int arr[] = {12, 34, 54, 2, 3}, i = 5;
cout<<"Print Arr[4] = "<<arr[4]<<"\nPrint i = "<<i;
return 0;
}
Then it will print:
Print Arr[4] = 3
Print i = 5
From the above code you can understand that the arr and i are separate variable.
int arr[] = {12, 34, 54, 2, 3}, i;
In this case it will give warning C4101: 'i' : unreferenced local variable. If you want to declare and initialize more than one variable in a line using ',' you have to follow same patter for compiler understanding.
for example,
int a = 2,b ; // warning C4101: 'b' : unreferenced local variable.
solution:1
int arr[] = {12, 34, 54, 2, 3}, i(0); // you may write i = 0;
If you initialize value than initialize for all variables of that line.
solution:2
int arr[] = {12, 34, 54, 2, 3};
int i;
And i recommend to you follow this rule for all datatype.
intvariable namediis declared here. `int a,b;, same thing.