C Data types

Data type is used to declare every c variables. because c compiler allocate memory according to data type when compile source code. every data type has are different role. they are capable to store different different amount of memory. programmer are utilize those variable according to our requirements. There is divided into following category.

C Data Types

Primitive data type :

1) char : char variable are stored only single character. there are basic data type of c programming. all c compiler are allocate memory of 1 bytes in char variable.

char variable_list;
Iteam Overview
char keyword
variable_list list of char variables
Scope When it defined. local char are inside of block, and global char are entire the program
Format specifier %c
2) int : int are store integer value. There are capable to store 2 bytes for 32 bit compiler ,and 4 bytes of 64 bit compiler. integer are declared in c programming as follows.

int variable_list;
Iteam Overview
int keyword
variable_list list of integer variables
scope When it defined. local integer are inside of block, and global integer are entire the program
Format specifier %d both signed and unsigned intger, %i for unsigned int.

For example.

 int age;

3) float : float are capable to store decimal floating point value with single precision.

float variable_list;
Iteam Overview
float keyword
variable_list list of floating variables
scope When it's defined. local float variable are inside of block, and global float are entire the program
Format specifier %f both signed and unsigned float

4) double: double are also store decimal value but there are capable to store double precision (floating point value).

double variable_list;
Iteam Overview
double keyword
variable_list list of double variables
scope When it's defined. local double variable are inside of block, and global double are entire the program
Format specifier %lf

5) void : void are empty data type. normally there are utilize in following place.

a) When function are not returning any values. for example.

  void print salary(int id){
  //code
  }
  void display_result(){
  //code
  }

b) when function are not accept any values. that is an optional to use void when function are not have parameter list.

  
  int message(void){
  //code
  }
  void display(void){
  //code
  }

c) there are utilized in pointer. for example.

/*
    Example of void data type
*/
//header file
#include <stdio.h>
// function declaration
void display(void);
int config(void);

void display(void){
    printf("Welcome to programming\n");
}
//in this case using of function argument
int config(void){
    return 1;
}
int main(){
   int status=config();
    void *ptr;
   if(status){
        display();// function call
        //assign address
        ptr=&status ;
        //print address of status variable
        printf("Value of ptr is : %p",ptr);
        //type cast and use
        printf("\nValue of *ptr is : %d",*((int*) ptr));
   }
    
}

Output

Welcome to programming
Value of ptr is : 0x7ffee35fd6bc
Value of *ptr is : 1

Sign qualifiers

integer and floating point variable is capable to stored both positive and negative values.

a) signed variable are storing both positive and negative values.

//32 bit compiler
signed char:  range  -128 to 127
signed int:  range  -2147483648 to 2147483647
signed short int:  range -32768 to 32767

b) unsigned are store only negative values

//32 bit compiler
Unsigned char:  from 0 to 255 
Unsigned int:  from 0 to 4294967295 
Unsigned short int:  from 0 to 65535  

Derived Data Types

Derived data type is combination of user defined data type like structure, union enumeration and arrays.

Arrays

C array

array is an data structure there are used to combine group of elements. view Array Post.

Structure (struct)

structure

Structure is a keyword, this are reliable to create user defined data type. for example array are store similar type of elements. similar way structure is capable to combine multiple different data in c programming. View Structure post.

Enumeration or (enum)

Enumeration

enum is keyword there is also called enumeration in c language. There can used to create user defined data type. they are consist of integer constant. view post Enumeration.

Union

C Union

union is keyword of c programming language. there are use to defined the user data type. view post Union.

© 2019, regularcodes.com, All rights reserved