M
miaohua1982
the code is as follows:
#include<stdio.h>
int arr[]={1,2,3,4,5,6,7};
#define size (sizeof(arr)/sizeof(arr[0]))
int main()
{
int index = -1;
int x = 0;
int t;
if( index < size - 1 )
x = arr[index+1];
printf("%d",x);
return 0;
}
then the value of x is 0, not 1. Maybe the type of "index" is promoted
to unsigned int ?so the type of "size" is unsigned int?How can I
decide the type of a const number by #define macro?Is there anyone
can tell me?
Thank you!
#include<stdio.h>
int arr[]={1,2,3,4,5,6,7};
#define size (sizeof(arr)/sizeof(arr[0]))
int main()
{
int index = -1;
int x = 0;
int t;
if( index < size - 1 )
x = arr[index+1];
printf("%d",x);
return 0;
}
then the value of x is 0, not 1. Maybe the type of "index" is promoted
to unsigned int ?so the type of "size" is unsigned int?How can I
decide the type of a const number by #define macro?Is there anyone
can tell me?
Thank you!