Thread: warning:comparison between pointer and integer

  1. #1
    Registered User
    Join Date
    May 2017
    Posts
    2

    Exclamation warning:comparison between pointer and integer

    Hi Guys,

    I am trying to compile a code which has the following code as part of it. Once I compile the code I got the following error message:
    warning:comparison between pointer and integer
    and the error lines are located on the word with red colour.
    Code:
    int payload[] ={ (random_rand() % 45)};
    
    
    if ((int*) payload < 20)
    { pr = 00; } 
    
    
    else if ((int*) payload >= 20 && (int*) payload <=25)
    { pr = 01;}     
      else if ((int*) payload > 25 && (int*) payload <=35)
      { pr = 10;}
      else { pr = 11}
    Is the way I compare the an integer array with an integer number correct? is there a better way to make a comparison?
    Thanks.
    Sul

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Why did you make payload an array to begin with?

    What's wrong with
    int payload = (random_rand() % 45);
    if ( payload < 20 )


    If you really want it to be an array, then you need to write
    if ( payload[0] < 20 )
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2017
    Posts
    2
    Thank you Salem for your quick reply. Yes I change to normal int variable and it works fine.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Comparison between pointer & integer
    By m88g88 in forum C Programming
    Replies: 5
    Last Post: 02-16-2010, 05:25 PM
  2. comparison pointer and integer
    By plodos in forum C Programming
    Replies: 19
    Last Post: 01-09-2009, 08:51 AM
  3. comparison between pointer and integer
    By R.Stiltskin in forum C Programming
    Replies: 13
    Last Post: 03-24-2007, 02:33 PM
  4. [Warning] comparison between pointer and integer
    By rkooij in forum C Programming
    Replies: 5
    Last Post: 05-12-2006, 08:43 AM
  5. Replies: 3
    Last Post: 03-27-2004, 06:33 PM

Tags for this Thread