• Register
1 vote
227 views

Problem:

I am getting an error from my very simple c++ program. It says invalid conversion from int to int*
What does it actually mean? Why I am experiencing this error? I am attaching my code snippet below. Please, check the code and fix the error if you can. 

#include <iostream>
using namespace std;
int main(){
}
int function(int myData[]){
    return myData;         //error produces here.
}

and the output I am getting is:

invalid conversion from `int*' to `int'

Many thanks for your effort and valuable time, guys.

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

2 votes
 
Best answer

Solution:

In your program, myData[ ] is an array and its return type is an integer. That’s why the compiler producing the error. To fix the error, either you need to convert the parameter an int 

int function(int myData){
    return myData;         //Now it looks good
}

Or convert the array to an integer before return it

int function(int myData[]){
    return myData[0];
}

You may follow any of those methods to avoid the error. Give them a try and let me know it still not works. Thanks.

13 9 6
94,240 points

Related questions

0 votes
1 answer 18 views
18 views
Problem: I get the error invalid conversion from 'const char*' to 'char*'. initializing argument 3 of 'void Printfunc(int, char*, char*)'on argument 3 of the function on the above line. The function is called as shown below void Printfunc(int a, char *loc, char *stream) please let me know if I need to change any initialization.
asked Dec 27, 2020 Mashhoodch 9.1k points
1 vote
1 answer 126 views
126 views
Problem: Hello Kodlogs, I am going through a problem for the last few minutes. I tried to solve it in many ways but still couldn&rsquo;t get rid of this. I&rsquo;ve learning c++ programming language from last week. So, you can treat me as a novice in it. I have a ... (addr,retstring().c_str()); And the function I tried to call: void Printfunc(int a, char *loc, char *stream) Thanks. Good day!
asked Mar 29, 2020 Gavin 15.3k points
0 votes
1 answer 1 view
1 view
Problem: How can I convert string into int after taking input ?
asked 2 hours ago Ashty 1.1k points
0 votes
1 answer 19 views
19 views asked Oct 16, 2020 SapperIt 1.2k points
0 votes
1 answer 5 views
0 votes
1 answer 6 views
6 views
Problem; how to read int from file c++
asked Feb 15 kaash_kashi 1.2k points
0 votes
1 answer 8 views
8 views
Problem: For example, if data in an external text file is like this: 45.78 67.90 87 34.89 346 0.98 How can I read this text file and assign each number to a variable in c++? Using ifstream, I am able to open the text file and assign first number to a variable, but I don't know how to read the next number after the spaces.
asked Dec 27, 2020 Mashhoodch 9.1k points
1 vote
1 answer 18 views
18 views
Problem: I am a new student in C++ programming. I am willing to write codes for a program that will read every integer value from my provided text file. I have a text document with a full of numerical values. It is really hard and hectic to find out all the values manually. ... is possible, how may I do this? I seek your help. Please help me if you can. I look forward to your answer. Many thanks.
asked May 19, 2020 adamSw 11.3k points
0 votes
1 answer 39 views
39 views
How can I solve this error?
asked Dec 19, 2020 TeamScript 13.5k points
0 votes
1 answer 515 views
515 views
Problem: I am very new to Java and trying to learn arrays in Java. I am trying to enter one int and the other long ex: 1 and 1000000000 and now I am trying to create the array of size 1000000000. And after creating the array at each index of my array willing to store int val, ex: arr[ ... [1]);     long []arr;        arr = new long[y+1];         for(long j=0;j<=y;j++)         arr[j] = 4;     }
asked Jul 29, 2020 Raphael Pacheco 4.9k points