HOME C C++ PYTHON JAVA HTML CSS JAVASCRIPT BOOTSTRAP JQUERY REACT PHP SQL AJAX JSON DATA SCIENCE AI

C Create Variables



A variable in C language is the name associated with some memory location to store data of different types. There are many types of variables in C depending on the scope, storage class, lifetime, type of data they store, etc. A variable is the basic building block of a C program that can be used in expressions as a substitute in place of the value it stores..


It is a way to represent memory location through symbol so that it can be easily identified.



Variables are containers for storing data values, like numbers and characters.

In C, there are different types of variables (defined with different keywords), for example:

int - The specific size of an int varies depending on the compiler and system architecture, but it's typically at least 16 bits (2 bytes) and can be 32 or even .

float -The size of a float is typically 4 bytes, or 32 bits. However, this can vary depending on the system architecture and compiler implementation.

char - stores single characters, such as 'a' or 'B'. Char values are surrounded by single quotes

double - Similar to float but with a higher precision, capable of storing larger decimal values. For example, double z = 123.456;.

_Bool - Represents boolean values, which can only be either 0 (false) or 1 (true). For example, _Bool flag = 1;.

long long - Represents very long integers, providing even larger storage capacity. For example, long long ll = 9223372036854775807LL;.,.




Declaring (Creating) Variables

In the C programming language, declaring (creating) variables is an essential step for storing and manipulating data in a program:

Example

type variableName = value;

Where type is one of C types (such as int), and variableName is the name of the variable (such as x or myName). The equal sign is used to assign a value to the variable.

So, to create a variable that should store a number, look at the following example:


Example
Create a variable called myNum of type int and assign the value 15 to it:

int myNum = 15;


You can also declare a variable without assigning the value, and assign the value later:


Example

// Declare a variable

int myNum;

// Assign a value to the variable

myNum = 15;


Output Variables

You learned from the output chapter that you can output values/print text with the printf() function:


Example

#include <stdio.h>

int main() {

printf("Hello CodeLines!");

return 0;

}


Output


Hello CodeLines!