Variables in C - Featured

Hello There, Here is about The Variables in C. Welcome to another episode of Express Learning Programming series. By Think & Free. Today in this lesson I’m gonna talk about Variables in C.

What is a Variable ?

The variable is a storage address or some memory location. It will allow us to store some known or unknown data with specific data-type. That means variables can hold some value with a specific data-type. we can use fewer, code and it will help to easily handle our program.

Variables In C

In the C first, we need to specify what is the datatype of our variable. And then we must give the identifier to our variable. The identifier is used to define a label or name for a variable. And then use the “=” symbol. finally, on the right side, we can put a value. Look at the code given below.

data_type identifier = value

Now I’m going to create a simple integer type variable and, I will show you how to read that value. here is the code.

#include <stdio.h>
int main()
{
    int num = 10;
    printf("%d", num);
    return 0;
}

I’m only explaining things in the main function. If you don’t have any idea about that, please refer to our previous lesson(First Program in C) before reading this.

int num = 10; is the first line, int is a data-type in C, used to define integer values. num is an identifier/label/name to our variable. see the right side of =. 10 is the value we assigned to our new variable.

How to Read a Variables in C?

Look at the “printf();” function. Something different in there. The first thing is “%d“, it called format specifiers.

Format Specifiers

format specifiers used to defines what type of data is used in Standard input and Standard output using “printf();” & “scanf();” functions. Here are some basic format specifiers, see the what datatype defines in “%d“, it was a Signed integer. Don’t think about that, I will explain that later.

Format SpecifierType
%cCharacter
%dSigned integer
%e or %EScientific notation of floats
%fFloat values
%g or %GSimilar as %e or %E
%hiSigned integer (short)
%huUnsigned Integer (short)
%iUnsigned integer
%l or %ld or %liLong
%lfDouble
%LfLong double
%luUnsigned int or unsigned long
%lli or %lldLong long
%lluUnsigned long long
%oOctal representation
%pPointer
%sString
%uUnsigned int
%x or %XHexadecimal representation
%nPrints nothing
%%Prints % character

finally, after the”,” symbol. Call to the variable using our variable name. let’s compile and run it you can see it will provide what is the value in the variable. In the next lesson, we are going to learn what are the data types we can use in GNU C Programming Language.

2 thoughts on “Express Learning Programming – Variables in C

Leave a Reply

Your email address will not be published. Required fields are marked *