🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to C Notes
Topic #9

C Variables


Variables

Variables are containers for storing data values, like numbers and characters.

You can think of a variable as a named box where you keep a value that can be used later.

In C, variables must have a specific type, which tells the program what kind of data the variable can store.

  • int - stores whole numbers (integers), such as 123 or -123
  • float - stores numbers with decimals, such as 19.99 or -19.99
  • char - stores a single character, such as 'a' or 'B'. Characters are surrounded by single quotes

Declaring (Creating) Variables

To create a variable, you must specify the type and give the variable a name.

You can also assign a value at the same time:

Syntax

type variableName = value;

Where type is one of the C data types (such as int), and variableName is the name you choose (for example x or myNum).

The equal sign = is used to assign a value to the variable.

So, to create a variable that should store a number, look at the following example:

Example

int myNum = 15;

You can also declare a variable first and assign a value later:

Example

// Declare a variable
int myNum;

// Assign a value later
myNum = 15;

Tip: Variable names should be meaningful, so your code is easier to understand.


Output Variables

You learned from the output chapter that you can print text using the printf() function:

Example

printf("Hello World!");

In many other programming languages (like Python, Java, and C++), you would normally use a print function to display the value of a variable. However, this is not possible in C:

Example

int myNum = 15;
printf(myNum); // This will cause an error

To print variables in C, you must use something called format specifiers.

Don't worry - this will be explained clearly in the next chapter.

Want to go beyond the notes?

Join CodingNow 2.0's C course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

C Variables – FAQs

Quick answers about learning C Variables in C.

This free note from CodingNow 2.0 explains C Variables in C — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every C topic on CodingNow 2.0, including C Variables, is 100% free with no signup required.
With focused practice, most students grasp C Variables in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now