Thursday 18 February 2021

Lec3: Data Types in C

 

Data Types in C

C has various data types to store data in program. C program can store integer, decimal number, character(alphabets), string(words or sentence), list etc. using various data types.


We need to specify the data type of variable(identifier) to store any data in it.


1. Primitives (Primary) Data Types

These data types store fundamental data used in the C programming.

  1. 1.int
  2. It is used to store integer values. C program compiled with GCC compiler (32-Bit) can store integers from -2147483648 to 2147483647. The size of int is compiler dependent. It takes 4 bytes in a 32-bit compiler such as GCC.

    intmyIntegerValue = 100;

  1. char
  2. It stores single character such as ‘a’, ‘Z’, ‘@’ etc. including number, symbol or special character. It takes 1 byte (8-bits) to store each character.

    charmyCharacter = 'A';

    Note: Every character has a corresponding ASCII value to it ranging from -128 to 127. Numbers as a character has their corresponding ASCII values too. For example, ‘1’ as char has ASCII value 49, ‘A’ has ASCII value 65.

  3. float
  4. It stores real numbers with precision upto 6 decimal places. It takes 4 bytes of memory and is also known as floating point number.

    floatmyFloatingValue = 100.6543;
  5. double
  6. It stores real numbers with precision upto 15 decimal places. It takes 8 bytes of memory.

    doublemyDoubleValue = 180.715586;


———————

Modifiers in C

These are keywords in C to modify the default properties of int and char data types. There are 4 modifiers in C as follows.

Modifiers In C

Modifiers In C

  1. short
  2. It limits user to store small integer values from -32768 to 32767. It can be used only on intdata type.

    shortintmyShortIntegerValue = 18;
  3. long
  4. It allows user to stores very large number (something like 9 Million Trillion) from -9223372036854775808 to 9223372036854775807. Syntax “long long” is used instead of “long int”.

    longlongmyLongIntegerValue = 827337203685421584;
  5. signed
  6. It is default modifier of int and char data type if no modifier is specified. It says that user can store negative and positive values.

    signedintmyNegativeIntegerValue = -544;signedintmypositiveIntegerValue = 544;/* Both of the statements have same meaning even without "signed" modifier*/
  7. unsigned
  8. When user intends to store only positive values in the given data type (int and char).

    unsignedintmyIntegerValue = 486;

———————-

Suze of program:







No comments:

Post a Comment