skydriver
skydriver

Reputation: 13

how to pass array of int to a function that accept array of float

I want pass an array of int to an array that have array of float parameter this is what I tried, it do compile but it give rubbish results !

function_1(float arr*, int len)
{
  ....
  ....
}

main()
{
     int samp[5] = {-1, 3, 5, 10, 20};
     function_1((float *)samp, 5); //not correct !
}

Upvotes: 0

Views: 377

Answers (1)

Some programmer dude
Some programmer dude

Reputation: 409196

You can't. No computer have the same internal and bitwise representation of float and int. Not to mention that sizeof(float) doesn't have to be equal to sizeof(int).

The only solution is to create a new array, and convert each and every element from int to float, and then pass the proper array of float.

Upvotes: 5

Related Questions