Hi i have an array - static int virtual_addr[10]=
-
{8196,34893,38583,22883,61843,43532,333,8448,2334,9492};
that i am trying to pass to a function - int determinePage(int virtual_addr){
-
int page_num;
-
int page_size = 4096;
-
-
page_num = floor(virtual_addr/page_size);
-
return page_num;
-
}
however I am getting errors.Any help would be appreciated
19 1601
You're passing an array of integers to the function, not a single integer. Your function signature should reflect that: int determinePage(int virtual_addr[])
Thnaks for your response.
However i still get errors
too few arguments to function int determinPage(int*)
and
invalid operands int* and int to binary operator /
Can you show us the full code, please?
well that is the code.
I have an array of initialized variables and i m trying to pass its values to the function so that i can divide each value by 4096 and return each value to the main function.
That isn't the complete code. You don't show how you're calling the function, etc., nor the updated function.
- int main()
-
{
-
cout << "Page Number is: " <<endl;
-
for (int i=0; i<10; i++){
-
cout <<determinePage()<< endl;
-
}
-
-
system("pause");
-
return 0;
-
}
however the error is generated in the function determinePage
Do you have any function prototyping?
If yes. Please post it.
Regards
Dheeraj Joshi
-
cout <<determinePage()<< endl;
-
You are calling a function without arguments.
and you say your function takes one argument. -
int determinePage(int virtual_addr[])
-
Regards
Dheeraj Joshi
Are you trying to pass one value at a time to functions from your array?
Regards
Dheeraj Joshi
yes but my immediate concern is how to correctly pass the parameter to the function without getting errors
yes i am passing one value at a time
Then array name and the parameter passed to the function can not be same.
It should be like. -
int determinePage(int virtual_addr_i) // Note the name of the variable is not same as array name
-
{
-
//Some stuff goes here
-
}
-
And function call must be like -
for (int i=0; i<10; i++)
-
{
-
cout <<determinePage(virtual_addr[i])<< endl;
-
}
-
Regards
Dheeraj Joshi
The array name and the function argument name can certainly be the same since they are in sifferent scopes.
However, the array name is a pointer to element 0. Therefore, the function argument has to be an int* and not an int.
@nlal
int determinePage(int virtual_addr){
int page_num;
int page_size = 4096; page_num = floor(virtual_addr/page_size);
return page_num;
}
your page_num = floor(virtual_addr/page_size)
is setting page_num = floor(array with 10 values divided by page_size);
you can't use an array like this, you have to pick a value from the array, or make a loop to use every value from the array. -
int determinePage(int virtual_addr[]) //<-- the [] MUST be in there
-
{
-
int page_num;
-
int page_size = 4096;
-
-
page_num = floor(virtual_addr[0]/page_size); // must choose one value from the array to use or it has ten values and can't use them all like this.
-
return page_num;
-
}
-
the function named floor(.......) used is not identified by c++ complier or is it user defined function?
IF you dont use the function floor(...) in your code then I made simple solution may it will help you. Thanks
#include<iostream>
using namespace std;
int determinePage(int);
int main()
{
int page_number;
static int virtual_addr[10]=
{8196,34893,38583,22883,61843,43532,333,8448,2334, 9492};
cout << "Page Number is: " <<endl;
for (int i=0; i<10; i++)
{
page_number = determinePage(virtual_addr[i]);
cout <<page_number<< endl;
}
system("pause");
return 0;
}
int determinePage(int virtual_addr)
{
int page_num;
int page_size = 4096;
page_num = virtual_addr/page_size;
return page_num;
}
out put:
Page Number is:
2
8
9
5
15
10
0
2
0
2
Press any key to continue . . .
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Raju V.K |
last post by:
I am developing a web site which requires a set og unique values be
transferred between pages and server many times. There fore i decided
to put the values in an array so that only one reference to...
|
by: BrianP |
last post by:
Hi,
I have had to invent a work-around to get past what looks like a
JavaScript bug, the malfunctioning Perl-like JavaScript array functions
including SPLICE() and UNSHIFT().
I have boiled it...
|
by: Oeleboele |
last post by:
OK, I can't understand this exactly:
I have this function: int howdy(void *)
I first past this to the function &aCharArray
I realized later that this should be aCharArray but...
the former...
|
by: DeepaK K C |
last post by:
Could anybody tell me how to pass array to a function by value?
-Deepak
|
by: Manish |
last post by:
Hi,
I m facing a problem in re-writing a code from VB to C #. We are using
a third party DLL to develop a application of Fax. The current
application is already written in VB and we have to...
|
by: DWalker |
last post by:
VBA, as used in Excel 2000 and Excel 2003, has a function called Array.
It's commonly seen in statements like the following:
Workbooks.OpenText Filename:=ACFileName, _
StartRow:=1,...
|
by: MLH |
last post by:
How would I modify the following to achieve a 2-dimensional array?
Dim MyWeek, MyDay
MyWeek = Array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")
' Return values assume lower bound set to 1...
|
by: tbringley |
last post by:
I am a c++ newbie, so please excuse the ignorance of this question.
I am interested in a way of having a class call a general member
function of another class.
Specifically, I am trying to...
|
by: shobu |
last post by:
passing array checkbox value and update the database <?include 'dbconnect.php'; error_reporting(0);$update_qr="update...
|
by: =?Utf-8?B?RGFya21hbg==?= |
last post by:
Hi,
I am wondering how you multi-dimension an array function?
My declared function looks like this:
Public Function GetCustomerList(ByVal Val1 As String, ByVal Val2 As Long,
ByVal Val3 As...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |