-3

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Phoenix
  • 467
  • 1
  • 11
  • 23

1 Answers1

1

What you are passing to a function is not an array. You are passing it a pointer.

SergeyA
  • 61,605
  • 5
  • 78
  • 137
  • i dont know what is a pointer... we have not done yet. According to me, i am passing an arry of value of b. – Phoenix Dec 04 '15 at 15:15
  • @Phoenix: Well, you are wrong. – Lightness Races in Orbit Dec 04 '15 at 15:30
  • so explain me... sir – Phoenix Dec 04 '15 at 15:51
  • What the other comments aren't explaining is this: you are seeing not the difference between Windows and Linux specifically, but the difference between a 64-bit operating system and a 32-bit one. In 64-bits systems, sizes of pointers are 8 bytes long, in 32-bits systems, 4 bytes. That is the result you're getting. Look it up. – Mr Lister Dec 08 '15 at 16:01