1. C Programming for Beginners: Writing Your First Hello World Program in C in 2023 2. Mastering Datatypes in C Programming: A Comprehensive Guide for Beginners in 2023 3. Complete Guide to % Format Specifiers in C for Beginners in 2023 4. A Comprehensive Guide to Operators in C Programming: Learn Everything About Operators in C in 2023 5. Master C Operator Precedence and Associativity in 2023: Definition, Examples, and Code 6. Learn Increment and Decrement Operators in C: A Beginners Guide with Examples - Codzify 7. Mastering Bitwise Operators in C: A Comprehensive Guide with Examples - Codzify 8. Ternary Operators in C Programming: A Beginners Guide (2023) 9. Switch Statements in C 2023: Complete Guide for Beginners 10. Learn Functions in C Programming - A Complete Tutorial for Beginners in 2023 11. Call by Value and Call by Reference in C Programming - A Complete Tutorial for Beginners in 2023 12. Storage Classes in C Programming: A Comprehensive Guide for 2023 13. Arrays in C Programming: A Comprehensive Guide for 2023 14. Basics of 2D Array in C Programming in 2023: Definition, Initialization, and Accessing Elements 15. Beginners Guide to Strings in C Programming with Codes and Examples 16. Strings Functions in C Language - strlen, strcpy,strcmp,strcat functions 17. A Comprehensive Guide to Structures in C Programming in 2023 18. Learn Unions in C Programming with Codes, Examples, and Explanations in 2023 19. Dynamic Memory Allocation in C: Understanding malloc, calloc, realloc, and free Functions 20. Introduction to C Programming 21. Hello world program in C 22. String functions in C - strncat, strcpy, strncpy, strchr, strrchr, strstr functions 23. Program for Fibonacci number in C - Codzify.com 24. What is palindrome number in C? 25. Write a C program to find a factorial of a given number 26. Write a C program to check whether a given number is prime or not 27. Write a C program to check whether a given number is an Armstrong number or not. 28. Write a C Program to transpose a matrix 29. C Programming Tutorial: Understanding Comments and Identifiers with Code Examples 30. Master String Handling Functions in C in 2023 - Codzify Topics

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.

Watch Video Tutorials at Codzify YouTube Channel:

Codzify Logo

Terms and Conditions    Cookie Policy   Refund Policy   Adsense Disclaimer

Contact: teamcodzify@gmail.com