C - Use a single variable x


Use a single variable x


#include <stdio.h> 

int main() //from  w w w .  j av  a2  s .  c  o  m
    int x; 

    x = 5; 
    printf("The value of variable x is %d.\n",x); 


Every variable used in C must be declared as a specific variable type and assigned a name.

The variable in the code above is declared as an integer (int) and given the name x.

Then the code assigns the value 5 to variable x.

The value goes on the right side of the equal sign. The variable goes on the left.

After that the code uses the variable's value in the printf() statement.

The %d conversion character is used because the variable contains an integer value.

The conversion character must match the variable.

Related Topic