Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Chapter 2: Variables and Data Types

In this chapter, we'll explore Variables and data types in C programming. Understanding variables and data types is essential for storing and manipulating different kinds of information in your programs. By the end of this chapter, you'll be familiar with declaring variables, assigning values, and performing operations using various data types in C.

Example:

#include


int main() {

   int age = 25;

   float Height = 1.75;

   char grade = 'A';


   printf("Age: %d\n", age);

   printf("Height: %.2f\n", height);

   printf("Grade: %c\n", grade);


   return 0;

}

Explanation:

We declare three variables: age of type int, height of type float, and grade of type char. We assign values to these variables: age is assigned 25, height is assigned 1.75, and grade is assigned 'A'. Using printf(), we display the values of these variables with appropriate format specifiers: %d for integers, %.2f for floats with two decimal places, and %c for characters.

To compile and run the program, follow the same steps as in the previous chapter.

In the next chapter, we'll dive into operators and expressions, which allow us to perform various calculations and comparisons in C programming. 



This post first appeared on Full Stack Web Developer, please read the originial post: here

Share the post

Chapter 2: Variables and Data Types

×

Subscribe to Full Stack Web Developer

Get updates delivered right to your inbox!

Thank you for your subscription

×