• Register
1 vote
365 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,260 points

Related questions

0 votes
1 answer 11 views
11 views
Problem: Is anyone available to assist me and resolve this issue? Invalid conversion from int* to int c++
asked May 6 Ifra 37.2k points
0 votes
1 answer 4 views
4 views
Problem: There's a bunch of threads about C++, but I'm stuck with regular C here and can't find an answer anywhere. I'm getting errors as the title states. 13 25 ~ [Error] invalid conversion from 'char' to 'const char*' [-fpermissive
asked Apr 13 ummesalma 29.2k points
0 votes
1 answer 49 views
49 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 13k points
0 votes
1 answer 9 views
9 views
Problem: Is anyone available to assist me and resolve this issue > Error: invalid conversion from 'const char*' to 'char' [-fpermissive]
asked 4 days ago ummeshani 10.8k points
0 votes
1 answer 9 views
9 views
Problem: How to fix, error: invalid conversion from const char* to char [-fpermissive] ?
asked Apr 15 Humaira ahmed 50.7k points
1 vote
1 answer 190 views
190 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
1 vote
1 answer 16 views
16 views
Problem : Why I receive this error message > "implicit conversion loses integer precision: 'time_t' (aka 'long') to 'unsigned int'"
asked Apr 26 Abik Dey 4k points
0 votes
1 answer 3 views
3 views
Problem: What should I do to fix this problem? > C++ deprecated conversion from string constant to &lsquo;char*&rsquo;
asked 3 days ago Junia Phoebe 15.3k points
1 vote
1 answer 25 views
25 views
Problem: According to C++11 standard This is invalid : char* p = "abc"; // valid in C, invalid in C++ And this is valid: char* p = (char*)"abc"; // OK: cast added Why ? What is the acutal difference is there in the second code that makes it valid ?
asked Apr 29 Raj Tyagi 15.6k points
0 votes
1 answer 48 views
48 views
Problem: Hello! I am trying to run the following code on my PC: #include<stdio.h> void main() { int number_1,number_2,result; char *operation; printf("Enter the first number: "); scanf("%d",&number_1); printf("Enter the second number: "); scanf("%d",&number_2) ... to know why is it giving these warnings? Moreover, what I can do to remove these warnings? Do they affect the working of my program?
asked Mar 17 Code Learner 9.9k points