I am learning c++ in school and we use linux ubuntu... we are learning oops and in oops we are doing classes right now.
I have two files, main file is called data.cpp and another is called mylib.h
my data.cpp file has this code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
#include "mylib.h"
int main() {
myclass myfile;int i,b=14;// if i change this value its give always me value for 8 in windows and in ubuntu 4
int arr[b];
//for(int i =0;i<b;i++){cout<<"Inserici Il numero : ";cin>>arr[i];}
i = myfile.trovaMax(arr);
cout <<"Arry Size "<<i<<endl;
cout<<endl;
return 0;
}
mylib.h file contain this code:
class myclass{
public:
int trovaMax (int num[]){
int curMax=sizeof(num);
/* for (int i = 0; i<sizeof(num);i++){
for(int j=0;j<i;j++){
if(curMax<num[j]){
curMax=num[j];
}//end if cond
}//end for j loop
}//end for i loop
*/ return curMax;
}
/* int findMinNum (int num[]){
int curMax=99999;
for (int i = 0; i<sizeof(num);i++){
for(int j=0;j<i;j++){
if(curMax>num[j]){
curMax=num[j];
}//end if cond
}//end for j loop
}//end for i loop
return curMax;
}
};
Problem: sizeof is give false value of an array that i pass in trovaMax funtion. In windows gives me always value 8 (if i change value of integer b in data.cpp file) And In linux always gives me value 4.
Now i am using windows at home.The program i am using is dev c++.
Note: I find this question, i did not find anywhere answer of this question.