C Data Types | My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Friday, May 31, 2019

C Data Types | My CS Tutorial

In C programming, a data type is a set of values ​​and is set to work on those values. C provides different types of data types that allow the programmer to select the appropriate type of variable so that its value can be determined.Each variable of C has an associated data type. Different data types require different amount of storage and there are specific operations that can be done on it.

In a programming language, there is a collection of data-type data that has specific meanings as well as attributes. Some of them are an integer, floating point, character, etc. Typically, programming languages ​​specify category values ​​for the given data-type.

C data types are used to :

  • When it is declared, then identify the type of a variable.
  • Identify the type of return value of a function.
  • Identify the type of parameter desired by a function.
In C language, data types are classified in some stages which are following.


  • Primitive DT :- int,float,char,void
  • Derived DT :- Array,Pointer,Function
  • User Defined DT :- enum,structure, union

Primitive Data Types


  • char: The most basic data type in C. It stores a single character and requires a single byte of memory.
  • int: an int variable is used to store an integer.
  • float: It is used to store decimal numbers (numbers with floating point value).
  • double: It is used to store decimal numbers (numbers with floating point value) with double precision.

Different data types also have different ranges upto which they can store numbers.we show this ranges
With format specifiers..

Data TypeMemory (bytes)RangeFormat Specifier
short int2-32,768 to 32,767%hd
unsigned short int20 to 65,535%hu
unsigned int40 to 4,294,967,295%u
int4-2,147,483,648 to 2,147,483,647%d
long int4-2,147,483,648 to 2,147,483,647%ld
unsigned long int40 to 4,294,967,295%lu
long long int8-(2^63) to (2^63)-1%lld
unsigned long long int80 to 18,446,744,073,709,551,615%llu
signed char1-128 to 127%c
unsigned char10 to 255%c
float4%f
double8%lf
long double12%Lf


Declaration of primitive Data Types with variables :-
int age; char letter; float height, width;

Derived Data Types

Array:- Arrays are sequences of data items having homogeneous values. They have adjacent memory locations to store values.

Pointer:- These are powerful C features which are used to access the memory and deal with their addresses.

User defined Data Types

Structure:-It is a package of different types of variables under one name. This is done efficiently to handle the data. The keyword "struct" is used to define a structure.

Union:-  allow different data types to be stored in the same storage location. Programmers can define a union with different members, but only one member can have one value at a given time.

Enum:-Enumeration is a special data type that has integral constants, and each of them is assigned with a specific name. The keyword "enum" is used to define enumerated data types.

No comments:

Post a Comment