Show List

Data Types and Variables

In C programming language, data types are used to define the type and size of data that a variable can store. The type of a variable determines how much memory space it will take up and what type of operations can be performed on it. Some of the most commonly used data types in C are:

  • int: The int data type is used to store integer values. For example, the following code declares an integer variable named age and assigns a value to it:
python
Copy code
int age = 28;
  • float: The float data type is used to store floating-point numbers with a single precision. For example:
css
Copy code
float height = 5.6;
  • double: The double data type is used to store floating-point numbers with double precision. For example:
java
Copy code
double weight = 160.5;
  • char: The char data type is used to store a single character. For example:
java
Copy code
char gender = 'M';
  • void: The void data type is used to specify that a function does not return a value.

In C, variables are used to store values in the memory. A variable must be declared before it is used in a program. The general syntax for declaring a variable in C is:

rust
Copy code
data_type variable_name;

For example, the following code declares an integer variable named age:

python
Copy code
int age;

After a variable is declared, you can assign a value to it using the assignment operator (=). For example:

python
Copy code
int age; age = 28;

You can also declare and assign a value to a variable in one line, like this:

python
Copy code
int age = 28;

    Leave a Comment


  • captcha text