Home

How to declare a variable in C

Declaring a variable in C language will be based on the datatype of that variable.

Declaring & Initializing variables in a program

The following code shows how we declare a variable and initialize it.

#include <stdio.h>
#include <conio.h>

void main ()
{
  int a = 2;
  float b = 3.4;
  char c = 'v';
  printf("%d\n%f\n%c\n", a, b, c);
  getch();
}

Declaring an integer variable

int numOfBooks;

Declaring a float variable

float price;

Declaring a character variable

char firstLetter;


Last Updated on

Next Post: GraphProtocol: TS2322 null assignment in Subgraph →

Comments