Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,945 questions

51,887 answers

573 users

How to declare, initialize and print specific data types in C

1 Answer

0 votes
#include <stdio.h> 
 
int main(int argc, char **argv)
{
    /*
     *
     * C data types
     
    _Bool 0 to 1 %d
    char –128 to 127 %c
    unsigned char 0 to 255 %u
    short int –32,768 to 32,767 %d
    unsigned short int 0 to 65,535 %u
    int –2,147,483,648 to 2,147,483,647 %d
    unsigned int 0 to 4,294,967,295 %u
    long int –2,147,483,648 to 2,147,483,647 %ld
    unsigned long int 0 to 4,294,967,295 %lu
    long long −9223372036854775807 to 9223372036854775807
    float 1.17×10–38 to 3.40×1038 %f
    double 2.22×10–308 to 1.79×10308 %lf
    long double (Same as double)
  */
    _Bool b = 1;
    char c = 'a';
    unsigned char uc = 250;
    short int si = 32000;
    unsigned short int usi = 65000;
    int i = 100000000;
    unsigned int ui = 4000000000;
    long int li = 2000000000;
    unsigned long int uli = 4294967295;
    long long ll = 9223372036854775807;
    float f = 1170.213;
    double d = 222000000000.5312;
    long double ld = 222000000000222000000000.5312;

    printf("_Bool b = %d\n", b);
    printf("char c = %c\n", c);
    printf("unsigned char uc = %u\n", uc);
    printf("short int si = %d\n", si);
    printf("unsigned short int usi = %u\n", usi);
    printf("int i = %d\n", i);
    printf("unsigned int ui = %u\n", ui);
    printf("long int li = %ld\n", li);
    printf("unsigned long int uli = %lu\n", uli);
    printf("long long ll = %llu\n", ll);
    printf("float f = %.3f\n", f);
    printf("double d = %.4lf\n", d);
    printf("long double ld = %.4le\n", ld);

    return 0;
}

/*
run:

_Bool b = 1
char c = a
unsigned char uc = 250
short int si = 32000
unsigned short int usi = 65000
i = 100000000
unsigned int ui = 4000000000
long int li = 2000000000
unsigned long int uli = 4294967295
long long ll = 9223372036854775807
float f = 1170.213
double d = 222000000000.5312
long double ld = -1.8009e-019

*/


answered Apr 14, 2015 by avibootz
edited Apr 14, 2015 by avibootz

Related questions

2 answers 155 views
1 answer 129 views
1 answer 249 views
1 answer 140 views
...