Mastering Datatypes in C Programming: A Comprehensive Guide for Beginners in 2023

Article by: Manish Methani

Last Updated: November 8, 2021 at 2:04pm IST
5 min 42 sec read

Data types in C programming are used to specify the type of data that a variable can hold. Each data type has a different size, range, and usage, and it is essential to understand them to write efficient and error-free code. Here's a tutorial to help you understand data types in C programming:

Step 1: Understanding Basic Datatypes

C programming has four basic datatypes: int, float, double, and char.

  • Int: Used for storing integer values.
  • Float: Used for storing floating-point values with single precision.
  • Double: Used for storing floating-point values with double precision.
  • Char: Used for storing a single character.

Here's an example of using basic datatypes in C programming:

#include <stdio.h>

int main() {
   int age = 30;
   float temperature = 36.5;
   double salary = 2000.50;
   char grade = 'A';

   printf("Age is %d", age);
   printf("Temperature is %.1f", temperature);
   printf("Salary is %.2lf", salary);
   printf("Grade is %c", grade);

   return 0;
}

Step 2: Understanding Derived Datatypes

Derived datatypes in C programming are created by combining basic datatypes or other derived datatypes.

  • Arrays: Used for storing a collection of values of the same type.
  • Pointers: Used for storing the memory address of a variable.
  • Structures: Used for storing a collection of variables of different types.

Here's an example of using derived datatypes in C programming:

#include <stdio.h>

int main() {
   int numbers[5] = {10, 20, 30, 40, 50};
   int *p;
   struct student {
      char name[50];
      int age;
      float gpa;
   };
   struct student s1 = {"John Doe", 20, 3.5};

   p = &numbers[0];

   printf("First element of the array: %d", *p);
   printf("Student name: %s", s1.name);
   printf("Student age: %d", s1.age);
   printf("Student GPA: %.1f", s1.gpa);

   return 0;
}

Output:

First element of the array: 10
Student name: John Doe
Student age: 20
Student GPA: 3.5

Step 3: Understanding Enumerated Datatypes

Enumerated data types in C programming are used to define a set of named constants.

Here's an example of using enumerated datatypes in C programming:

 #include <stdio.h>

enum week { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday };

int main() {
   enum week today = Monday;

   printf("Today is %d", today);

   return 0;
}

Output:

Today is 0

In conclusion, datatypes are an essential concept in C programming. By following this tutorial, you have learned about basic, derived, and enumerated datatypes in C programming and how to use them effectively with code examples.

Simplified Coding for Beginners.








Download the Codzify
Mobile App


Mobile App Development, Web App Development, Programming Languages, Latest Tech News & lot more.

Codzify Mobile App

A self-paced learning Courses Created by an Engineer
For Engineers.

Premium

The Complete Angular Course

Instructor: Manish Methani

Explore Curriculum
Free

C Programming for Absolute Beginners

Instructor: Manish Methani

Start Watching
Premium

Flutter Mobile App Development Course

Instructor: Manish Methani

Explore Curriculum
Free

Learn HTML, CSS & Bootstrap

Instructor: Manish Methani

Start Watching

Test your skills with these expert-led curated
Mock Tests.

C Programming Test

Test your C Programming skills with this comprehensive mock test on C Programming.

Take Test

Flutter Test

Solve most asked Interview Questions on Flutter and Test your foundational skills in flutter.

Take Test

GATE(CSE) Operating Systems

Solve most asked GATE Questions in Operating Systems and test your Gate Score.

Take Test

HTML,CSS Test

This is a mock test designed to help you assess your knowledge and skills in HTML and CSS.

Take Test

(GATE CSE) Data Structures & Algorithms Test

Solve most asked GATE Questions in Data Structures and Algorithms and test your Gate Score.

Take Test
include_once 'codzify-footer.php'; ?>