473,385 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Invalid conversion from 'int*' to 'int' question

Hi guys, I have a quick question. The language I'm using is C.

The question I'm tackling:
Write a program that
(1) defines a 1D array with ten int elements, and
(2) sets the values of the elements such that they are equal to the addresses of the elements, and
(3) prints out the content of the elements.
The program should call a user-defined function value_address with the following function prototype: void value_address( int[] )

My answer:

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. int main(void)
  3. {
  4.     int array[10], i;
  5.     void value_address(int[]);
  6.  
  7.     value_address(array);
  8.  
  9.     for (i=0;i<10;i++)
  10.         printf("Value of array[%1d] is %d\n", i, array[i]);
  11.  
  12.     return 0;
  13. }
  14.  
  15. /* function definition for value_address */
  16. void value_address(int inarray[])
  17. {
  18.      int i;
  19.      for (i=0;i<10;i++)
  20.         inarray[i] = &inarray[i];
  21. }

I'm getting an error message Invalid conversion from 'int*' to 'int' on the line below
inarray[i] = &inarray[i];
What am I doing wrong?

Thanks :)
Oct 28 '07 #1
1 16009
JosAH
11,448 Expert 8TB
Write a program that
(1) defines a 1D array with ten int elements, and
(2) sets the values of the elements such that they are equal to the addresses of the elements, and
(3) prints out the content of the elements.
The program should call a user-defined function value_address with the following function prototype: void value_address( int[] )

[ ... ]

I'm getting an error message Invalid conversion from 'int*' to 'int' on the line below
inarray[i] = &inarray[i];
What am I doing wrong?

Thanks :)
You're not doing anything wrong: question 2) sucks, i.e. an int can't contain an
address because ints are not guaranteed to be able to contain the value of an
int* (a pointer to an int).

kind regards,

Jos
Oct 28 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Russell Reagan | last post by:
In a newer version of a chess program I am writing, I have created classes that are (more or less) drop in replacements for things that used to be plain old integer or enumerated variables (colors,...
30
by: Tim Johansson | last post by:
I'm new to C++, and tried to start making a script that will shuffle an array. Can someone please tell me what's wrong? #include <iostream.h> #include <string.h> int main () {...
6
by: Thomas Barth | last post by:
Hi, I'm new to windows programming and still reading a book about windows-programming with C++. I copied the following code from the book into my ide (Eclipse/CDT) to comprehend the code, but two...
8
by: Abhijit Bhadra | last post by:
Hi , I am using gcc version 3.3.2. While compiling this code struct sockaddr_in *CBaseSocket::GetSocketName() { socklen_t iLen; cCriticalSocket.Lock(); //...
10
by: jeff regoord | last post by:
A user inputs a float value. The scanf() function gets the value. However, I need to create an error handler with an if else statement saying invalid input if the input is not a number. Does...
31
by: Bjørn Augestad | last post by:
Below is a program which converts a double to an integer in two different ways, giving me two different values for the int. The basic expression is 1.0 / (1.0 * 365.0) which should be 365, but one...
11
by: Martin Jørgensen | last post by:
Hi, I'm using this alloc_mem-function: - - - - - - - - - - - - - - - - - - - - - - - - void *alloc_mem (size_t num_elems, size_t elem_size, char *filename, int line, size_t *total_mem) {
2
by: tkirankumar | last post by:
Hi all, uname -a SunOS cbmrsd1a1 5.10 Generic_118833-17 sun4us sparc FJSV,GPUZC-M g++ -v Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.10/3.3.2/specs Configured with:...
3
by: fazulu deen | last post by:
Hi all, For the following code : file_ptr = fopen("pass_fail.txt", "a"); // error line 393 fdisplay(file_ptr, "Test Passed"); fclose(file_ptr);
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
0
BarryA
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...
0
Oralloy
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.