Skip to content
Utopper skill
  • ProgrammingExpand
    • Programming Examples
  • Interview QuestionsExpand
    • DevOps Interview Questions
    • Android Interview Questions
  • How to
  • Tools
  • Top 10
  • Book Summaries
Utopper skill

Data Type in C Programming

C Programming Course

Page Index


C Overview

C Environmental Setup

C Program Structure

C Basic Syntax

C Programming Blocks

C Printf and Scanf

C Data Type

C Variables

C Constant

C Keywords

C Operators

C Comments

C Identifier

C Literals

C Tokens

C Format Specifier

ASCII Value in C

C If Statement

C If Else Statement

C Nested If Statement

C Switch Case

C Nested Switch

C If Else vs Switch

C Loops

C For Loop

C While Loop

C Do While Loop

Nested Loop in C

Infinite Loop in C

C Break

C Continue

C goto

Typecasting in C

C Function Basic

Call By Value

Call By Reference

Recursion in C

Storage Classes

C Array Basics

1-D Array in C

2-D Array in C

Passing Array to Function

Return Array from a Function

Multi-Dimensional Array in C

Pointer to an Array in C

C Pointer

Pointer Arithmetic

Array of Pointers

C Pointer to Pointer

Passing Pointer to Function in C

Return Pointer From Function in C

Dangling Pointer in C

sizeof() Operators in C

Const Pointers in C

Void Pointer in C

C Deference Pointer

Null Pointer in C

C Function Pointer

C String Basics

C gets() and puts()

C String Function

C Structure Basics

typedef in C

C Bit Fields

C Array of Structure

C Nested Structure

Structure Padding in C

C Union

C File Handling Basics

C fprintf() fscanf()

C fputc() fgetc()

C fputs() fgets()

C fseek()

C rewind()

C ftell()

C Preprocessor Basics

C Macros

C #include

C #define

C #undef

C #ifdef()

C #ifndef()

Data type refers to the classification of data used in a program. It specifies the type of data that a variable can hold, the operations that can be performed on the variable, and the way the variable is stored in memory.

Classification of data type in c programming :

1. Primitive data types: These are the basic data types that are built into the language and are used to represent simple data values. They include:

Primitive data types are basic data types that are built into programming languages and cannot be broken down into simpler components. They are also often referred to as simple data types.

Here are some examples of primitive data types:

  1. Integer: This is a data type used to represent whole numbers, such as 1, 2, 3, -4, -5, etc. In most programming languages, integers are represented using the “int” keyword. For example:
int age = 25;
short num = 10;
long population = 1000000L;
long long bigNumber = 9223372036854775807LL;

2. Float: This is a data type used to represent decimal numbers with single precision, such as 3.14, 2.0, etc. In most programming languages, floats are represented using the “float” keyword. For example:

float price = 3.99f;
double pi = 3.14159265358979323846;
long double hugeNum = 1.23456789012345678901234567890L;

3. Double: This is a data type used to represent decimal numbers with double precision, such as 3.14159265359, 2.71828, etc. In most programming languages, doubles are represented using the “double” keyword. For example:

double gravity = 9.81;

4. Boolean: This is a data type used to represent true/false values. In most programming languages, booleans are represented using the “bool” keyword. For example:

bool isTall = true;
bool isSmart = false;

5. Character: This is a data type used to represent single characters, such as ‘a’, ‘b’, ‘c’, ‘A’, ‘B’, etc. In most programming languages, characters are represented using the “char” keyword. For example:

char letter = 'A';
char symbol = '$';
char newline = '\n';

These are just a few examples of primitive data types. Other primitive data types include byte, short, long, and void (in some programming languages).

2. Derived data types: These are data types that are created by combining primitive data types or by modifying them in some way. They include:

In C programming, derived data types are created by combining or modifying primitive data types or other derived data types. Here are some examples of derived data types:

1. Array data type:

An array is a derived data type that allows the storage of a collection of data items of the same type. For example:

int numbers[5] = {1, 2, 3, 4, 5};

In this example, numbers is an array of integers that can hold 5 values. The values {1, 2, 3, 4, 5} are assigned to the elements of the array.

2. Pointer data type:

A pointer is a derived data type that stores the memory address of another variable. For example:

int age = 25;
int *agePointer = &age;

In this example, agePointer is a pointer to an integer that stores the memory address of the variable age.

3. Structure data type:

A structure is a derived data type that allows the storage of a collection of data items of different types that are grouped together under a single name. For example:

struct person {
  char name[50];
  int age;
  float height;
};

struct person john = {"John", 25, 1.82};

In this example, person is a structure that contains three members: a character array name, an integer age, and a float height. The variable john is defined as a person structure and initialized with the values {"John", 25, 1.82}.

4. Union data type:

A union is a derived data type that allows the storage of different data types in the same memory location. For example:

union data {
  int i;
  float f;
  char c;
};

union data value;
value.i = 10;
printf("value.i = %d\n", value.i);
value.f = 2.5;
printf("value.f = %f\n", value.f);
value.c = 'A';
printf("value.c = %c\n", value.c);

In this example, data is a union that can hold an integer i, a float f, or a character c. The variable value is a data union, and the values {10, 2.5, 'A'} are assigned to the members of the union.

5. Enumeration data type:

An enumeration is a derived data type that consists of a set of named integer constants. For example:

enum weekday {
  MONDAY,
  TUESDAY,
  WEDNESDAY,
  THURSDAY,
  FRIDAY,
  SATURDAY,
  SUNDAY
};

enum weekday today = TUESDAY;
printf("Today is %d\n", today);

In this example, weekday is an enumeration that defines the names of the days of the week as integer constants. The variable today is defined as a weekday enumeration and assigned the value TUESDAY.

Data Type in Table View :

Data TypeStorage SizeValue Range
char1 byte-128 to 127 or 0 to 255
int2 or 4 bytes-32,768 to 32,767 or -2,147,483,648 to 2,147,483,647
short2 bytes-32,768 to 32,767
long4 bytes-2,147,483,648 to 2,147,483,647
long long8 bytes-(2^63) to (2^63)-1
float4 bytes1.2E-38 to 3.4E+38
double8 bytes2.3E-308 to 1.7E+308
long double10 or 16 bytes3.4E-4932 to 1.1E+4932
_Bool1 byte0 or 1

Example that demonstrates the usage of primitive data types in C:

#include <stdio.h>
int main() {
    // Declare and initialize int, float, double, and char variables
    int age = 30;
    float height = 5.9;
    double weight = 160.5;
    char first_initial = 'A';
    _Bool is_student = 0; // 0 for false, 1 for true

    // Print the values of these variables
    printf("Age: %d\n", age);
    printf("Height: %.1f\n", height);
    printf("Weight: %.1lf\n", weight);
    printf("First initial: %c\n", first_initial);
    printf("Is student? %s\n", is_student ? "Yes" : "No");

    return 0;
}

This code initializes and prints the values of several primitive data types, including int, float, double, char, and _Bool. The printf function is used to display the values, with the appropriate format specifiers for each data type:

  • %d: int
  • %.1f: float (with one decimal place)
  • %.1lf: double (with one decimal place)
  • %c: char
  • %s: string (used here to display “Yes” or “No” based on the boolean value)

Output :

Age: 30
Height: 5.9
Weight: 160.5
First initial: A
Is student? No

Our Latest Posts

  • Git Interview Questions
    35 + GIT Interview Questions
  • Book Summary of Why We Sleep By Matthew Walker
    Book Summary of Why We Sleep By Matthew Walker
  • C Program to Print Your Own Name
    C Program to Print Your Own Name with Example
  • Facebook
  • Instagram
  • YouTube
  • Telegram
  • LinkedIn
  • Twitter

Mail : [email protected]

Privacy Policy | DISCLAIMER | Contact Us

Learn Development

learn HTML

learn CSS

learn JavaScript

Examples

C Examples

C++ Examples

Java Examples

Study Material

Interview Questions

How to

Hosting

SEO

Blogging

© 2023 Utopper.com

All Rights Reserved with Copyright & Registered TradeMarks
OWNED BY : GROWTH EDUCATION SOLUTIONS PRIVATE LIMITED

Scroll to top
  • Programming
    • Programming Examples
  • Interview Questions
    • DevOps Interview Questions
    • Android Interview Questions
  • How to
  • Tools
  • Top 10
  • Book Summaries
Search