C Programs consists of many things. Some important things to know before writing and practicing C programs are Variables, Datatypes and Operators. There are many other things which you need to know as well, but for now we will discuss about these only. In future, while writing new codes we will discuss about other theories/topics when they are required.
In programming, a Variable is a Container of Data. It is the name of the memory location assigned for a specific purpose. It can be re-used as many times as required and it’s values can be changed as well. It is a way to represent memory location through symbol so that it can be easily identified.
In simple terms, a Variable is a is a storage place which has some memory location allocated to it. There are different types of variables which require different types of memory and are used to store different types of data.
char c, arr;
Declaration of a Variable :
A typical Variable is written / declared like this :
In case of multiple variable declaration of similar type :
varibale_type variable1_name, variable2_name, variable3_name;
Here, we first we write what type/kind of variable we want to declare and then the name we want to give the variable.
Here, we are declaring a variable of integer type named ‘result’.
Datatypes of Variables :
There are many kinds of Variables. These are generally called Datatypes. Such as :
- char: Can hold/store a character in it.
- int: Used to hold an integer.
- float: Used to hold a float value.
There are many more kinds of variables we just saw a few of them. We will discuss about the Datatypes more in the next post.
Rules to Define/Name a Variable :
- Variable name must not start with a digit.
- Variable name can consist of alphabets, digits and special symbols like underscore
- Blank or spaces are not allowed in variable name (Underscores ‘_’ can be used. Such as : variable_name).
- Keywords are not allowed as variable name.
- Upper and lower case names are treated as different, as C is case-sensitive, so it is suggested to keep the variable names in lower case.
What is a ‘Keyword’ ?Keywords are predefined, reserved words used in programming that have special meanings to the compiler. Keywords are part of the syntax and they cannot be used as an identifier (names of variables).
In future posts we will discuss more about Datatypes, Keywords and Reserved Words, Operators etc.
Please write comments if you find anything incorrect, helpful, questions or you want to share more information about the topic discussed above.
Arijit Banerjee is a Passionate Web Developer and a Cyber Security Enthusiast.