I am running a C++ program from the command line on Bash, which is in a Linux environment. I am curious how you pass in a parameter from the command line. Here is my program:
#include <iostream>
using namespace std;
int large_pow2( int n );
int main()
{
int value = 15;
int largest_power = large_pow2(value);
cout << "The highest power of 2 in " << value << " is " << large_power << "." << endl;
return 0;
}
int large_pow2( int n )
{
int i = n
int j = i & (i - 1);
while( j != 0)
{
i = j;
j = i & (i - 1);
}
return j;
}
After I compile the program I want to be able to use the command line to pass in a number to use for value. For instance, to run the program you type ./"program_name" where "program_name" is the name of my program without quotes. Is there a way to set value = n or something? When I run the program let's say I want n to be 20 so on the command line I type something like ./"program_name" 20. Then the program would run with n = 20. Is there a way to do that? I am completely new to a Linux environment and Bash so don't quite know how to do things in it yet.
mains parameters.