Home Contact About

Assigning values to Storage class






To create a variable, specify the type and assign it a value:
Syntax
type variable_name = 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:
int mynum = 15;


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

//Declare a Variable
int My_num;
//Assign value to variable
My_num = 15;

Reading Data from Keyword
Another way of giving values to variables is to take input from the user and process it.


Syntax of scanf
  • scanf("control string", &variable1, &variable2,...);