Learn C data types | basic information in c language data types very easily

C Data Types

In this instructional exercise, you will find out about essential information types, for example, int, coast, roast and so forth in C programming. 

In C programming, information types are revelations for factors. This decides the sort and size of information related with factors. For instance,
int myVar;
Here, myVar is a variable of int (integer) type. The size of int is 4 bytes.
Every factor in C has a related information type. Every datum type requires various measures of memory and has some particular tasks which can be performed over it. Let us quickly portray them individually: 

Following are the instances of some normal information types utilized in C:
  • char: The most basic data type in C. It stores a single character and requires a single byte of memory in almost all compilers.
  • int: As the name suggests, an int variable is used to store an integer.
  • float: It is used to store decimal numbers (numbers with floating point value) with single precision.
  • double: It is used to store decimal numbers (numbers with floating point value) with double precision.
Various information types additionally have various extents upto which they can store numbers. These reaches may shift from compiler to compiler. The following is rundown of reaches alongside the memory necessity and arrangement specifiers on 32 bit gcc compiler.

DATA TYPE                               

MEMORY (BYTES)                         

      RANGE                                     

FORMAT SPECIFIER                  

short int

2

-32,768 to 32,767

%hd

unsigned short int

2

0 to 65,535

%hu

unsigned int

4

0 to 4,294,967,295

%u

int

4

-2,147,483,648 to 2,147,483,647

%d

long int

4

-2,147,483,648 to 2,147,483,647

%ld

unsigned long int

4

0 to 4,294,967,295

%lu

long long int

8

-(2^63) to (2^63)-1

%lld

unsigned long long int

8

0 to 18,446,744,073,709,551,615

%llu

signed char

1

-128 to 127

%c

unsigned char

1

0 to 255

%c

float

4

%f

double

8

%lf

long double

12

%Lf

 

Basic code of c language data type:

#include <stdio.h> 
 int main() 
   { 
int a = 1; 
char b ='G'; 
double c = 3.14; 
printf("Hello World!\n"); 

//printing the variables defined above along with their sizes 
printf("Hello! I am a character. My value is %c and "
"my size is %lu byte.\n", b,sizeof(char)); 
//can use sizeof(b) above as well 

printf("Hello! I am an integer. My value is %d and "
"my size is %lu bytes.\n", a,sizeof(int)); 
//can use sizeof(a) above as well 

printf("Hello! I am a double floating point variable."
" My value is %lf and my size is %lu bytes.\n",c,sizeof(double)); 
//can use sizeof(c) above as well 

printf("Bye! See you soon. :)\n"); 

return 0; 
    }  

No comments

Powered by Blogger.