Variable and data types in c Programming || c language notes

Variable and data types in c Programming || c language notes

 Variable and data types in c Programming

C is a powerful programming language that is widely used in the field of software development. In C programming, variables and data types are crucial concepts that every developer needs to understand. In this article, we will discuss these two concepts in detail.

variable and data types in c


Variables in C:


A variable is a container that stores a value or a set of values. In C programming, we use variables to hold different types of data such as integers, characters, and floating-point numbers. Before using a variable in C, it needs to be declared with a data type, and the syntax for declaring a variable is as follows:

< data_type > < variable_name >;

For example, to declare an integer variable named "age," we use the following statement:

int age;

Here, "int" is the data type, and "age" is the variable name. The semicolon at the end of the statement indicates the end of the declaration.

Data Types in C:


Data types in C programming are used to define the type of data that a variable can hold. There are different types of data types available in C, and they are classified into two categories: primary data types and derived data types.

Primary Data Types:


Primary data types are the basic data types in C, and they include:

Integer: It is used to store integer values, and it is represented by the "int" keyword.

Character: It is used to store a single character, and it is represented by the "char" keyword.

Floating-point: It is used to store decimal values, and it is represented by the "float" and "double" keywords.

Void: It is used to represent the absence of a value, and it is represented by the "void" keyword.


Let's dive a little deeper into the different types of data types in C programming.

Integer:


Integers are used to store whole numbers. They can be either positive or negative. In C programming, the "int" keyword is used to declare integer variables. The size of the integer data type is machine-dependent, but it is typically 2 or 4 bytes.
For example:

int age = 30;

Character:
Characters are used to store single characters. In C programming, the "char" keyword is used to declare character variables. The size of the character data type is 1 byte.
For example:

char grade = 'A';

Floating-point:


Floating-point data types are used to store decimal values. In C programming, there are two types of floating-point data types: float and double. The "float" keyword is used to declare float variables, and the "double" keyword is used to declare double variables. The size of the float data type is 4 bytes, and the size of the double data type is 8 bytes.
For example:

float salary = 5000.50;
double pi = 3.14159;

Void:


The "void" data type is used to represent the absence of a value. It is typically used in function declarations where there is no return value. For example:
void printMessage() {
printf("Hello, world!");
}


Derived Data Types:


Derived data types are created by combining primary data types or other derived data types, and they include:

Array: It is a collection of similar data types, and it is represented by the "[]" brackets.

Pointer: It is used to store the memory address of a variable, and it is represented by the "*" symbol.

Structure: It is a collection of different data types, and it is represented by the "struct" keyword.

Union: It is a special data type that allows storing different data types in the same memory location, and it is represented by the "union" keyword.

Conclusion:


Variables and data types are crucial concepts in C programming that every developer needs to understand. In this article, we discussed the concept of variables and different data types available in C programming. With the knowledge of these concepts, developers can create efficient and effective C programs.

 

Watch Video: 

 

 

All C  Topics : -

  1. C Language Intro

  2. Structure of C Language 

  3. Variable & data Types 

  4. Printf and Scanf Function

  5. Operator in c Language 

  6. If Statement in c Language 

  7. If else and Nasted if in C

  8. Switch Case In C 

  9. While loop in C Language 

  10. Exit Control Loop (Do While)

  11. For Loop in c 

  12. C Language Pratice Program 

  13. Goto Statement in c Programming 

  14. Array in c

  15. Pointer in  c Language 

  16. String in c Language 
Post a Comment (0)
Previous Post Next Post