VARIABLES AND DATATYPES IN C

0


 VARIABLES AND DATATYPES IN C


GAIN AND SHINE


Variables in C Programming Language

    Variables are the building blocks of any program. In C programming language, variables are used to store data such as numbers, characters, and arrays. Variables in C are declared with a specific data type, which determines the size and type of data that can be stored in the variable. In this blog post, we will discuss variables in C programming language in detail.


Declaring Variables in C

    To declare a variable in C, we need to specify the data type of the variable, followed by the variable name.

Here's an example:
  int myVariable;

    In this example, we declare a variable named myVariable of data type int. We can also initialize the variable with a value like this:

  int myVariable = 10;

    In this example, we declare a variable named myVariable of data type int and initialize it with the value 10.


Data Types in C

    C programming language supports several data types, which can be divided into two categories: primitive data types and derived data types. Here are the most commonly used data types in C:


Primitive Data Types:

Integer :- This data type is used to store whole numbers, both positive and negative. It can be declared using the 'int' keyword.

Floating-point :- This data type is used to store decimal numbers, both positive and negative. It can be declared using the float or 'double' keyword.

Character :- This data type is used to store a single character. It can be declared using the 'char' keyword.

Boolean :- This data type is used to store true or false values. It can be declared using the 'bool' keyword.


Derived Data Types:

Arrays :- This data type is used to store a collection of values of the same data type. It can be declared using the data type followed by square brackets, such as int 'myArray[10]'.

Structures :- This data type is used to store a collection of values of different data types. It can be declared using the 'struct' keyword.

Pointers :- This data type is used to store the memory address of a variable. It can be declared using the '*' symbol.


Using Variables in C

To use a variable in C, we simply refer to its name.

Here's an example :
  int x = 5;
  
int y = 10;
  int result = x+y;
}

    In this example, we declare two variables x and y of data type int and assign them the values '5' and '10', respectively. We then declare another variable result of data type int and assign it the sum of 'x' and 'y'.



Conclusion

    Variables and data types are fundamental concepts in C programming language. In this blog post, we discussed the most commonly used data types in C, including primitive and derived data types, and how to declare and use variables in C. By understanding these concepts, you will be able to write efficient and effective C programs.


Post a Comment

0Comments

Share Your Feedback Here !!

Post a Comment (0)