Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What data type is a whole number in #define?

Tags:

c

If I use a whole number in #define, what data type is it considered to be in sprintf() in C99 ?

#define NUMBER 100

sprintf(buf, "%i\n", NUMBER); // is it %i, %u, %lu ?
like image 554
Jane S Avatar asked Dec 01 '12 18:12

Jane S


People also ask

What datatype is a number with a decimal?

Decimal Data Type. The decimal data type is an exact numeric data type defined by its precision (total number of digits) and scale (number of digits to the right of the decimal point).

Which data type is a whole number in Python?

Integers – This value is represented by int class. It contains positive or negative whole numbers (without fraction or decimal). In Python there is no limit to how long an integer value can be.


1 Answers

#define NUMBER1 100 /* int: use "%d" or "%i" in printf() */
#define NUMBER2 100U /* unsigned int: use "%u" in printf() */
#define NUMBER3 100L /* long int: use "%ld" or "%li" in printf() */
#define NUMBER4 100UL /* unsigned long int: use "%lu" in printf() */
/* C99 */
#define NUMBER5 100LL /* long long int: use "%lld" or "%lli" in printf() */
#define NUMBER6 100ULL /* unsigned long long int: use "%llu" in printf() */

Note: the U and L can also be in lowercase
Note2: the U can come before or after the L or LL

like image 159
pmg Avatar answered Sep 28 '22 22:09

pmg