Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. error: invalid operands to binary / (have ‘float’ and ‘int *’)

error: invalid operands to binary / (have ‘float’ and ‘int *’)

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mybm1
    wrote on last edited by
    #1

    Quote:

    error: invalid operands to binary / (have ‘float’ and ‘int *’)

    how to solve this error?

    E 1 Reply Last reply
    0
    • M mybm1

      Quote:

      error: invalid operands to binary / (have ‘float’ and ‘int *’)

      how to solve this error?

      E Offline
      E Offline
      enhzflep
      wrote on last edited by
      #2

      You can't divide by a pointer. You can divide by what it points to, but you cant divide the pointer itself. Take a look at the following. Basically, you need to dereference the pointer, as I've done in #3.

      #include <cstdio>

      int main()
      {
      int numerator = 10;
      float denominator = 2.7;

      // 1. Using no pointers
      float result = numerator / denominator;
      printf("%d / %f = %f\\n", numerator, denominator, result);
      
      
      
      // 2. Using pointers incorrectly
      int \*ptrToNumerator;
      ptrToNumerator = &numerator;
      // below line causes the following error:
      // error: invalid operands of types 'int\*' and 'float' to binary 'operator/'|
      result = ptrToNumerator / denominator;
      printf("%f\\n", result);
      
      
      
      // 3. Using pointers appropriately
      result = \*ptrToNumerator / denominator;
      printf("%f\\n", result);
      
      return 0;
      

      }

      M 1 Reply Last reply
      0
      • E enhzflep

        You can't divide by a pointer. You can divide by what it points to, but you cant divide the pointer itself. Take a look at the following. Basically, you need to dereference the pointer, as I've done in #3.

        #include <cstdio>

        int main()
        {
        int numerator = 10;
        float denominator = 2.7;

        // 1. Using no pointers
        float result = numerator / denominator;
        printf("%d / %f = %f\\n", numerator, denominator, result);
        
        
        
        // 2. Using pointers incorrectly
        int \*ptrToNumerator;
        ptrToNumerator = &numerator;
        // below line causes the following error:
        // error: invalid operands of types 'int\*' and 'float' to binary 'operator/'|
        result = ptrToNumerator / denominator;
        printf("%f\\n", result);
        
        
        
        // 3. Using pointers appropriately
        result = \*ptrToNumerator / denominator;
        printf("%f\\n", result);
        
        return 0;
        

        }

        M Offline
        M Offline
        mybm1
        wrote on last edited by
        #3

        Quote:

        for(i=0;i<*SizeOfData;i++)
        {
        datasample[i]=square(samplesValue1[i]);
        squaring1=(datasample[i]*datasample[i]);
        sum +=squaring1;
        }
        summation_input=(float)sum/ *SizeOfData;
        printf("\n%f",summation_input);

        fclose(fp);

        wen i change summation_input=(float)sum/SizeOfData; to summation_input=(float)sum/ *SizeOfData some unknown error is generating given below

        Quote:

        dithermain.c:(.text+0x430): undefined reference to `square' collect2: ld returned 1 exit status

        E 1 Reply Last reply
        0
        • M mybm1

          Quote:

          for(i=0;i<*SizeOfData;i++)
          {
          datasample[i]=square(samplesValue1[i]);
          squaring1=(datasample[i]*datasample[i]);
          sum +=squaring1;
          }
          summation_input=(float)sum/ *SizeOfData;
          printf("\n%f",summation_input);

          fclose(fp);

          wen i change summation_input=(float)sum/SizeOfData; to summation_input=(float)sum/ *SizeOfData some unknown error is generating given below

          Quote:

          dithermain.c:(.text+0x430): undefined reference to `square' collect2: ld returned 1 exit status

          E Offline
          E Offline
          enhzflep
          wrote on last edited by
          #4

          That error is telling you that the linker can't find the function body for your function square. If it's in another c/cpp file, you have to compile and link it too. Otherwise, you can just place the square function in the same c/cpp file, but make sure it appears before it's first used. (otherwise you'll get a compiler error that says the symbol is unrecognized)

          M 1 Reply Last reply
          0
          • E enhzflep

            That error is telling you that the linker can't find the function body for your function square. If it's in another c/cpp file, you have to compile and link it too. Otherwise, you can just place the square function in the same c/cpp file, but make sure it appears before it's first used. (otherwise you'll get a compiler error that says the symbol is unrecognized)

            M Offline
            M Offline
            mybm1
            wrote on last edited by
            #5

            in function after writing return(); is it possible to continue process will it be effective ?

            D 1 Reply Last reply
            0
            • M mybm1

              in function after writing return(); is it possible to continue process will it be effective ?

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              maibam debina wrote:

              in function after writing return(); is it possible to continue process...

              Not in that same function.

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups