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 <stdio.h>


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. 

No comments:

Post a Comment

Chapter 10: File Handling

  File handling is crucial for reading from and writing to files in C programming. In this chapter, we'll dive into file handling and un...