Skip to content
thesarfo

Note

C: Variables

Declaring variables in C, and the printf format specifier basics.

views 0
#include <stdio.h>
int main(void){
int i; /* signed integer */
float f; /* signed floating point numbers */
i = 2;
printf("Hello my number is %d", i);
return 0;
}

All variables must be declared at the beginning of the function before they are used. Declaration means announcing the data type and the name of the variable.

int i, float f means the fahr and celsius variables are of type integer and float.

Using the assignment operator, we have stored something inside the i variable, but to print it out, we need to pass two parameters in the printf function:

  1. format string
  2. value to print (variable)

char — character: single byte short — short int long — long int double — double-precision float