Specifying Integer Constants with int type literal - C Data Type

C examples for Data Type:int

Introduction

To declare and initialize the long type variable Big_Number, you could write this:

Demo Code


#include <stdio.h>

int main(void)
{
    long Big_Number = 1287600L;

    printf("%d",Big_Number);
    return 0;/*from   w w  w  .j  ava 2s. co m*/
}

  

Result

You write negative integer constants with a minus sign, for example:

Demo Code

#include <stdio.h> 
  
int main(void) 
{ 
    int decrease = -4; 
    long  level = -100000L; 
  
    printf("%d",decrease);
    return 0; //w w  w .  j ava  2s  .  co  m
} 
  

Result

You specify integer constants to be of type long long by appending two Ls:

Demo Code

#include <stdio.h> 
  
int main(void) 
{ 
    long long big_number = 123456789LL;

    printf("%d",big_number);
    /*w w w .ja v  a2  s  .co m*/
    return 0;
}

To specify a constant to be of an unsigned type, you append a U, as in these examples:

Demo Code

#include <stdio.h> 
  
int main(void) 
{ 
    unsigned int count = 100U;
    unsigned long value = 999999999UL;

    printf("%d",value);
    //from   www  . j a  va2s.  c  om
    return 0;
}

Result

To store integers with the largest magnitude, you could define a variable as the following example.

The ULL specifies that the initial value is type unsigned long long.

Demo Code

#include <stdio.h> 
  
int main(void) { 
    unsigned long long metersPerLightYear = 9460730472580800ULL;

    printf("%d",metersPerLightYear);
    /*w w  w.j av  a2s. c  o m*/
    return 0;
}

Related Tutorials