How to Declare Variable in C Programming - learnit

Home Top Ad

Post Top Ad

Saturday, April 10, 2021

How to Declare Variable in C Programming

How to Declare Variable in C Programming

How to Declare Variable in C Programming

C Variable

C variable is a named location in a memory where a program can manipulate the data. This location is used to hold the value of the variable.

The value of the C variable may get change in the program.

C variable might be belonging to any of the data type like int, float, char etc.


RULES FOR NAMING C VARIABLE

1.Variable name must begin with letter or underscore.

2.Variables are case sensitive

3.They can be constructed with digits, letters.

4.No special symbols are allowed other than underscore.

5.sum, height, _value are some examples for variable name


DECLARING & INITIALIZING C VARIABLE

1)Variables should be declared in the C program before to use.

2)Memory space is not allocated for a variable while declaration. It happens only on variable definition.

3)Variable initialization means assigning a value to the variable.

Type Syntax
Variable declaration data_type variable_name;
Example: int i, j, z; char name, Gender;
Variable initialization data_type variable_name = value;
Example: int i = 20, j= 40,z=10; char name = ‘M’, Gender=’F’;

THERE ARE THREE TYPES OF VARIABLES IN C PROGRAM THEY ARE

1.Local variable

2.Global variable

3.Environment variable


Example:

#include<stdio.h>
#include<conio.h>
#include<float.h>
main()
{
int a;
float b;
char c[35]="Knowledge Education Cambodia";
i=20;
j=40;
printf("Value Number a=%d",a);
printf("\n");
printf("Value Number b=%f",b);
printf("\n");
printf("String %s",c);
getch();
}

Please Watching My Video is Below

No comments:

Post a Comment

Post Top Ad