1 of 11

Data Types in C

PRESENTED BY MINAKSHI SHARMA

2 of 11

�In C programming, data types specify the type of data a variable can hold. They specify the size, memory allocation, and operations that can be performed on variables. �

3 of 11

Categories of Data Types in C

1. Basic Data Types:- Used to store fundamental types of data such as integers, floating-point numbers, and characters.

  • Examples: int, float, char, double.

​

2. Derived Data Types:- Derived from basic data types.

  • Examples: Arrays, Pointers, Functions.

​

3. Enumeration Data Types:- Used to define a set of named integer constants.

  • Example: enum.

​

4. User-Defined Data Types:- Created by the programmer for specific needs.

  • Examples: struct, union, typedef.

​

4 of 11

Integers:-Used for whole numbers.�(Non decimal values)

​

  • Types of integers:
  • Signed integers: Can store positive and negative values.
  • Unsigned integers: Can store only non-negative values, doubling the range of positive numbers.

​

5 of 11

Integers types

6 of 11

Float types:-

​

  • Used for storing real numbers with fractional parts.
  • Higher precision requires larger data types.

7 of 11

Char types:-

​

  • Used to store single characters.
  • Character literals are enclosed in single quotes ex:-’A’.

8 of 11

Strings

In C, strings are represented as arrays of characters ending with a null terminator '\0'.

This null terminator indicates the end of the string in memory.

Declaration and Initialization of Strings

  • Using a character array:

​

char str1[20] = "Hello, World!";

​

9 of 11

Key Points About Strings

  1. Strings are mutable if declared as a character array.

​

  • Functions like strlen, strcpy, strcat, and strcmp from the <string.h> library are used to manipulate strings.

​

  • A pointer to a string (char *str) points to a string literal, which is immutable.

​

10 of 11

Booleans in C�

C does not have a dedicated boolean type in its standard you can use integers (0 for false and any non-zero value for true) to represent boolean values.

​

#include <stdio.h> #include <stdbool.h> int main()

{

bool isTrue = true;

bool isFalse = false;

11 of 11